diff --git a/src/commands/migrations/v0_29_1.ts b/src/commands/migrations/v0_29_1.ts index 38b677d6c..28927d6ad 100644 --- a/src/commands/migrations/v0_29_1.ts +++ b/src/commands/migrations/v0_29_1.ts @@ -45,10 +45,15 @@ async function phaseBBackfill(opts: OrchestratorOpts): Promise 0) { + await engine.disconnect(); return { name: 'verify', status: 'failed', detail: `${remaining} pages still have NULL effective_date (backfill incomplete)`, }; } + await engine.disconnect(); return { name: 'verify', status: 'complete', detail: '0 pages with NULL effective_date' }; } catch (e) { return { name: 'verify', status: 'failed', detail: e instanceof Error ? e.message : String(e) }; diff --git a/src/core/pglite-schema.ts b/src/core/pglite-schema.ts index 942f734c0..8ff4a36a8 100644 --- a/src/core/pglite-schema.ts +++ b/src/core/pglite-schema.ts @@ -92,8 +92,16 @@ CREATE INDEX IF NOT EXISTS idx_pages_source_id ON pages(source_id); CREATE INDEX IF NOT EXISTS pages_deleted_at_purge_idx ON pages (deleted_at) WHERE deleted_at IS NOT NULL; -- v0.29.1: expression index for since/until date-range filters. -CREATE INDEX IF NOT EXISTS pages_coalesce_date_idx - ON pages ((COALESCE(effective_date, updated_at))); +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_name = 'pages' AND column_name = 'effective_date' + ) THEN + EXECUTE 'CREATE INDEX IF NOT EXISTS pages_coalesce_date_idx ON pages ((COALESCE(effective_date, updated_at)))'; + END IF; +END $$; -- ============================================================ -- content_chunks: chunked content with embeddings diff --git a/src/core/schema-embedded.ts b/src/core/schema-embedded.ts index 905936657..7217708aa 100644 --- a/src/core/schema-embedded.ts +++ b/src/core/schema-embedded.ts @@ -124,8 +124,16 @@ CREATE INDEX IF NOT EXISTS pages_deleted_at_purge_idx -- COALESCE(effective_date, updated_at). A partial index on effective_date -- alone would NOT help — the planner can't use it for the negative side of -- the COALESCE. Expression index is what actually accelerates the filter. -CREATE INDEX IF NOT EXISTS pages_coalesce_date_idx - ON pages ((COALESCE(effective_date, updated_at))); +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_name = 'pages' AND column_name = 'effective_date' + ) THEN + EXECUTE 'CREATE INDEX IF NOT EXISTS pages_coalesce_date_idx ON pages ((COALESCE(effective_date, updated_at)))'; + END IF; +END $$; -- ============================================================ -- content_chunks: chunked content with embeddings diff --git a/src/schema.sql b/src/schema.sql index e059d539f..754cca47f 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -120,8 +120,16 @@ CREATE INDEX IF NOT EXISTS pages_deleted_at_purge_idx -- COALESCE(effective_date, updated_at). A partial index on effective_date -- alone would NOT help — the planner can't use it for the negative side of -- the COALESCE. Expression index is what actually accelerates the filter. -CREATE INDEX IF NOT EXISTS pages_coalesce_date_idx - ON pages ((COALESCE(effective_date, updated_at))); +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_name = 'pages' AND column_name = 'effective_date' + ) THEN + EXECUTE 'CREATE INDEX IF NOT EXISTS pages_coalesce_date_idx ON pages ((COALESCE(effective_date, updated_at)))'; + END IF; +END $$; -- ============================================================ -- content_chunks: chunked content with embeddings