fix(migration): ensure pg_trgm is created before trigram index in 000041

Migration 000002 creates the pg_trgm extension only inside the conditional
embeddings block guarded by app.skip_embedding. Deployments that use a
non-postgres retrieve driver (Qdrant, Elasticsearch, Milvus, etc.) skip
that block entirely, so pg_trgm is never installed. When migration 000041
then runs CREATE INDEX ... USING GIN (lower(title) gin_trgm_ops) the
statement fails and the whole migration is rolled back, leaving
task_pending_ops and task_dead_letters uncreated. The application keeps
starting (migrations are best-effort), but wiki ingest enqueue silently
fails and wiki pages are never produced.

Re-issue CREATE EXTENSION IF NOT EXISTS pg_trgm at the top of 000041 so
the extension is guaranteed present at the moment the trigram index is
created. The statement is idempotent on environments where 000002 already
installed it, and surfaces a clear, early error on environments where the
extension genuinely cannot be loaded.

Fixes #1319.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wizardchen
2026-05-14 16:13:05 +08:00
committed by lyingbug
parent d7b5835519
commit 3a0a0cff9c
@@ -20,6 +20,17 @@
DO $$ BEGIN RAISE NOTICE '[Migration 000041] Applying task queue + wiki indexes schema'; END $$;
-- Ensure pg_trgm is loaded before creating the trigram GIN index below.
-- Migration 000002 also creates this extension, but only inside the
-- conditional embeddings block (app.skip_embedding gate). Environments that
-- skip 000002's body — or had pg_trgm install silently fail there — would
-- otherwise blow up on the gin_trgm_ops index further down. Re-issuing
-- CREATE EXTENSION IF NOT EXISTS here is a no-op when it's already present
-- and surfaces a clear error early when the extension genuinely isn't
-- available, instead of failing midway and leaving task_pending_ops /
-- task_dead_letters uncreated (see issue #1319).
CREATE EXTENSION IF NOT EXISTS pg_trgm;
-- ---------------------------------------------------------------------------
-- 1) task_pending_ops
--