fix(search): make pg_bigm migration graceful when extension unavailable

CI uses pgvector/pgvector:pg17 which doesn't ship pg_bigm. Wrap
CREATE EXTENSION and index creation in DO/EXCEPTION blocks so the
migration succeeds without pg_bigm — indexes are skipped and search
falls back to plain LIKE scans.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
yushen
2026-04-09 14:00:03 +08:00
parent b484b78cbd
commit a2a021a0dd
2 changed files with 26 additions and 7 deletions

View File

@@ -1,8 +1,20 @@
-- Enable pg_bigm extension for bigram-based full-text search (CJK-friendly).
CREATE EXTENSION IF NOT EXISTS pg_bigm;
-- Skips gracefully if pg_bigm is not available (e.g. CI environments).
DO $$
BEGIN
CREATE EXTENSION IF NOT EXISTS pg_bigm;
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'pg_bigm not available, skipping bigram indexes';
END
$$;
-- GIN index on issue title for LIKE '%keyword%' queries.
CREATE INDEX idx_issue_title_bigm ON issue USING gin (title gin_bigm_ops);
-- GIN index on issue description (nullable, use COALESCE).
CREATE INDEX idx_issue_description_bigm ON issue USING gin (COALESCE(description, '') gin_bigm_ops);
-- GIN indexes on issue title/description for LIKE '%keyword%' queries.
-- Only created when pg_bigm is installed.
DO $$
BEGIN
CREATE INDEX idx_issue_title_bigm ON issue USING gin (title gin_bigm_ops);
CREATE INDEX idx_issue_description_bigm ON issue USING gin (COALESCE(description, '') gin_bigm_ops);
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'skipping bigram indexes (pg_bigm not installed)';
END
$$;

View File

@@ -1,2 +1,9 @@
-- GIN index on comment content for LIKE '%keyword%' queries (pg_bigm).
CREATE INDEX idx_comment_content_bigm ON comment USING gin (content gin_bigm_ops);
-- Only created when pg_bigm is installed.
DO $$
BEGIN
CREATE INDEX idx_comment_content_bigm ON comment USING gin (content gin_bigm_ops);
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'skipping bigram index on comment (pg_bigm not installed)';
END
$$;