ALTER TABLE "analytics_jobs" ADD COLUMN "payload" jsonb;--> statement-breakpoint
ALTER TABLE "keywords" ADD COLUMN "semantic" jsonb;--> statement-breakpoint
-- Custom migration (S3 serp-semantics): extend lz4 TOAST compression to the
-- new `keywords.semantic` column — same rationale as 0024_keywords_toast_lz4 /
-- 0055_audit_gsc_toast_lz4 (lz4 decompresses near-free vs pglz, usually stores
-- smaller too). Metadata-only DDL — existing rows are NOT recompressed, only
-- new writes take lz4.
--
-- lz4 requires Postgres compiled --with-lz4 (PG >= 14); the official Docker
-- images (prod) are. On a build without it the ALTER raises
-- feature_not_supported, so the column is guarded to degrade to a no-op
-- NOTICE instead of hard-failing the migration chain.
DO $$
BEGIN
  ALTER TABLE keywords ALTER COLUMN semantic SET COMPRESSION lz4;
EXCEPTION
  WHEN feature_not_supported THEN
    RAISE NOTICE 'lz4 TOAST compression not supported by this Postgres build; keeping default (pglz). Rebuild --with-lz4 (or use the official Docker image) to enable.';
END $$;
