Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix: make release index migrations concurrent (#4995)
Multica Eve75e8bd5b64f6
diff --git a/server/migrations/134_search_index_trgm_fallback.down.sql b/server/migrations/134_search_index_trgm_fallback.down.sqldeleted file mode 100644index add5ef8493..0000000000--- a/server/migrations/134_search_index_trgm_fallback.down.sql+++ /dev/null@@ -1,10 +0,0 @@--- Drop the pg_trgm fallback GIN search indexes. Leaves the pg_trgm--- extension in place because other future queries may depend on it and--- dropping it has no benefit (extension idle overhead is essentially--- zero). The pg_bigm indexes from migrations 036 / 039 are untouched.--DROP INDEX IF EXISTS idx_issue_title_trgm;-DROP INDEX IF EXISTS idx_issue_description_trgm;-DROP INDEX IF EXISTS idx_comment_content_trgm;-DROP INDEX IF EXISTS idx_project_title_trgm;-DROP INDEX IF EXISTS idx_project_description_trgm;diff --git a/server/migrations/134_search_index_trgm_fallback.up.sql b/server/migrations/134_search_index_trgm_fallback.up.sqldeleted file mode 100644index c5350e58e6..0000000000--- a/server/migrations/134_search_index_trgm_fallback.up.sql+++ /dev/null@@ -1,85 +0,0 @@--- Fallback GIN search indexes using pg_trgm for environments where pg_bigm--- is unavailable. Background:------ Migration 032 (issue_search_index), 033 (comment_search_index), and--- 039 (project_search_index) all wrap `CREATE EXTENSION pg_bigm` and--- their GIN index creation in EXCEPTION handlers, silently skipping if--- pg_bigm is not installed. This was intended as a CI guardrail (see--- migration 032 header) so tests could run against a stock Postgres image.------ The unintended consequence: the bundled self-host / dev / CI Postgres--- image is `pgvector/pgvector:pg17`, which does NOT ship pg_bigm. On every--- self-hosted deployment the three migrations silently no-op, no GIN--- indexes get built, and search queries fall back to a Seq Scan on--- `issue` / `project` + correlated Seq Scans on `comment` — verified with--- EXPLAIN on the local dev DB, which had zero title/description/comment--- search indexes before this change.------ pg_trgm is part of PostgreSQL's contrib package and is shipped in every--- image we support, including pgvector. It supports the same--- `LOWER(col) LIKE '%pattern%'` pattern via GIN + gin_trgm_ops. For CJK--- content pg_bigm remains the better choice (bigrams vs trigrams — a--- 2-character CJK query indexes cleanly under pg_bigm but degrades to a--- Seq Scan under pg_trgm) so we do NOT drop the pg_bigm indexes; the two--- coexist and the planner picks whichever is cheaper.------ Coverage MUST match the search handler surface: SearchIssues consults--- issue.title / issue.description / comment.content; SearchProjects--- consults project.title / project.description. Missing any one of them--- leaves that branch on a Seq Scan and defeats the point of the fallback.------ Guardrails:--- 1. `CREATE EXTENSION IF NOT EXISTS pg_trgm` — safe on all supported--- images. Wrapped in DO/EXCEPTION so a hypothetical minimal image--- without pg_trgm still lets migrations finish (mirrors migration--- 032 pg_bigm pattern).--- 2. `CREATE INDEX IF NOT EXISTS` — idempotent on re-run.--- 3. Same LOWER() expression signature as the search handlers' WHERE--- clauses exactly, so the planner can match the index.------ Lock impact: plain CREATE INDEX takes an AccessExclusive lock on the--- table for the duration of the build. Cannot use CREATE INDEX--- CONCURRENTLY here because it is disallowed inside a DO block (and--- the extension-optional guardrail requires DO). Operators running very--- large tables who want the concurrent variant can pre-create the five--- indexes manually with CONCURRENTLY before applying the migration; the--- IF NOT EXISTS check will then turn this migration into a no-op.--DO $$-BEGIN- CREATE EXTENSION IF NOT EXISTS pg_trgm;-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'pg_trgm not available, skipping trigram search indexes';-END-$$;--DO $$-BEGIN- CREATE INDEX IF NOT EXISTS idx_issue_title_trgm- ON issue USING gin (LOWER(title) gin_trgm_ops);- CREATE INDEX IF NOT EXISTS idx_issue_description_trgm- ON issue USING gin (LOWER(COALESCE(description, '')) gin_trgm_ops);-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'skipping trigram indexes on issue (pg_trgm not installed)';-END-$$;--DO $$-BEGIN- CREATE INDEX IF NOT EXISTS idx_comment_content_trgm- ON comment USING gin (LOWER(content) gin_trgm_ops);-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'skipping trigram index on comment (pg_trgm not installed)';-END-$$;--DO $$-BEGIN- CREATE INDEX IF NOT EXISTS idx_project_title_trgm- ON project USING gin (LOWER(title) gin_trgm_ops);- CREATE INDEX IF NOT EXISTS idx_project_description_trgm- ON project USING gin (LOWER(COALESCE(description, '')) gin_trgm_ops);-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'skipping trigram indexes on project (pg_trgm not installed)';-END-$$;diff --git a/server/migrations/135_comment_workspace_index.down.sql b/server/migrations/135_comment_workspace_index.down.sqlindex 36029d4956..56e01ea7a1 100644--- a/server/migrations/135_comment_workspace_index.down.sql+++ b/server/migrations/135_comment_workspace_index.down.sql@@ -5,4 +5,4 @@-- down migration if operating below the query-rewrite change; otherwise-- expect search latency to regress.-DROP INDEX IF EXISTS idx_comment_workspace;+DROP INDEX CONCURRENTLY IF EXISTS idx_comment_workspace;diff --git a/server/migrations/135_comment_workspace_index.up.sql b/server/migrations/135_comment_workspace_index.up.sqlindex 586ee1c127..bdd31a064c 100644--- a/server/migrations/135_comment_workspace_index.up.sql+++ b/server/migrations/135_comment_workspace_index.up.sql@@ -35,14 +35,12 @@-- where pg_bigm was absent the migration "succeeded" while quietly-- creating no indexes at all — the exact silent-skip pattern that took-- prd search down. This index is the critical support for the fix, not--- an optional CJK bonus, so a real failure (lock timeout, disk full,--- permission denied, schema drift) MUST abort the migration and fail--- deployment, not slip through as a green success. IF NOT EXISTS keeps--- the migration idempotent for the operator-precreated case; operators--- who need concurrent creation on a large prd table should run--- `CREATE INDEX CONCURRENTLY idx_comment_workspace ON comment--- (workspace_id);` before applying, which turns this statement into a--- no-op.+-- an optional CJK bonus, so a real failure (disk full, permission denied,+-- schema drift) MUST abort the migration and fail+-- deployment, not slip through as a green success. CONCURRENTLY avoids+-- blocking writes on the hot comment table while the index builds; this+-- file must stay single-statement because Postgres rejects CREATE INDEX+-- CONCURRENTLY in a transaction or multi-command string.-CREATE INDEX IF NOT EXISTS idx_comment_workspace+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_comment_workspaceON comment (workspace_id);diff --git a/server/migrations/137_search_index_pg_trgm_extension.down.sql b/server/migrations/137_search_index_pg_trgm_extension.down.sqlnew file mode 100644index 0000000000..9fc0750345--- /dev/null+++ b/server/migrations/137_search_index_pg_trgm_extension.down.sql@@ -0,0 +1,3 @@+-- Leave pg_trgm installed. Other queries or operator-created indexes may depend+-- on it, and an idle extension has no meaningful overhead.+SELECT 1;diff --git a/server/migrations/137_search_index_pg_trgm_extension.up.sql b/server/migrations/137_search_index_pg_trgm_extension.up.sqlnew file mode 100644index 0000000000..e965b17e4f--- /dev/null+++ b/server/migrations/137_search_index_pg_trgm_extension.up.sql@@ -0,0 +1,4 @@+-- Install pg_trgm for the fallback trigram search indexes added in the next+-- migrations. Keep this separate from CREATE INDEX CONCURRENTLY files:+-- Postgres rejects concurrent index builds in a multi-statement migration.+CREATE EXTENSION IF NOT EXISTS pg_trgm;diff --git a/server/migrations/138_issue_title_trgm_index.down.sql b/server/migrations/138_issue_title_trgm_index.down.sqlnew file mode 100644index 0000000000..49d95c1ac4--- /dev/null+++ b/server/migrations/138_issue_title_trgm_index.down.sql@@ -0,0 +1 @@+DROP INDEX CONCURRENTLY IF EXISTS idx_issue_title_trgm;diff --git a/server/migrations/138_issue_title_trgm_index.up.sql b/server/migrations/138_issue_title_trgm_index.up.sqlnew file mode 100644index 0000000000..b4b6ff6505--- /dev/null+++ b/server/migrations/138_issue_title_trgm_index.up.sql@@ -0,0 +1,5 @@+-- Fallback GIN index for SearchIssues title LIKE matches when pg_bigm is not+-- available. This must stay as a single-statement migration because CREATE+-- INDEX CONCURRENTLY cannot run inside a transaction or multi-command string.+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_issue_title_trgm+ ON issue USING gin (LOWER(title) gin_trgm_ops);diff --git a/server/migrations/139_issue_description_trgm_index.down.sql b/server/migrations/139_issue_description_trgm_index.down.sqlnew file mode 100644index 0000000000..f94dab6d93--- /dev/null+++ b/server/migrations/139_issue_description_trgm_index.down.sql@@ -0,0 +1 @@+DROP INDEX CONCURRENTLY IF EXISTS idx_issue_description_trgm;diff --git a/server/migrations/139_issue_description_trgm_index.up.sql b/server/migrations/139_issue_description_trgm_index.up.sqlnew file mode 100644index 0000000000..cebb1833be--- /dev/null+++ b/server/migrations/139_issue_description_trgm_index.up.sql@@ -0,0 +1,4 @@+-- Fallback GIN index for SearchIssues description LIKE matches when pg_bigm is+-- not available. Single-statement file required for CREATE INDEX CONCURRENTLY.+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_issue_description_trgm+ ON issue USING gin (LOWER(COALESCE(description, '')) gin_trgm_ops);diff --git a/server/migrations/140_comment_content_trgm_index.down.sql b/server/migrations/140_comment_content_trgm_index.down.sqlnew file mode 100644index 0000000000..6f4e1010c8--- /dev/null+++ b/server/migrations/140_comment_content_trgm_index.down.sql@@ -0,0 +1 @@+DROP INDEX CONCURRENTLY IF EXISTS idx_comment_content_trgm;diff --git a/server/migrations/140_comment_content_trgm_index.up.sql b/server/migrations/140_comment_content_trgm_index.up.sqlnew file mode 100644index 0000000000..ee237babcb--- /dev/null+++ b/server/migrations/140_comment_content_trgm_index.up.sql@@ -0,0 +1,5 @@+-- Fallback GIN index for SearchIssues comment content LIKE matches when+-- pg_bigm is not available. Single-statement file required for CREATE INDEX+-- CONCURRENTLY.+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_comment_content_trgm+ ON comment USING gin (LOWER(content) gin_trgm_ops);diff --git a/server/migrations/141_project_title_trgm_index.down.sql b/server/migrations/141_project_title_trgm_index.down.sqlnew file mode 100644index 0000000000..07fa2017f0--- /dev/null+++ b/server/migrations/141_project_title_trgm_index.down.sql@@ -0,0 +1 @@+DROP INDEX CONCURRENTLY IF EXISTS idx_project_title_trgm;diff --git a/server/migrations/141_project_title_trgm_index.up.sql b/server/migrations/141_project_title_trgm_index.up.sqlnew file mode 100644index 0000000000..39e34e4ef6--- /dev/null+++ b/server/migrations/141_project_title_trgm_index.up.sql@@ -0,0 +1,4 @@+-- Fallback GIN index for SearchProjects title LIKE matches when pg_bigm is not+-- available. Single-statement file required for CREATE INDEX CONCURRENTLY.+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_project_title_trgm+ ON project USING gin (LOWER(title) gin_trgm_ops);diff --git a/server/migrations/142_project_description_trgm_index.down.sql b/server/migrations/142_project_description_trgm_index.down.sqlnew file mode 100644index 0000000000..48686aa280--- /dev/null+++ b/server/migrations/142_project_description_trgm_index.down.sql@@ -0,0 +1 @@+DROP INDEX CONCURRENTLY IF EXISTS idx_project_description_trgm;diff --git a/server/migrations/142_project_description_trgm_index.up.sql b/server/migrations/142_project_description_trgm_index.up.sqlnew file mode 100644index 0000000000..3c9e033852--- /dev/null+++ b/server/migrations/142_project_description_trgm_index.up.sql@@ -0,0 +1,5 @@+-- Fallback GIN index for SearchProjects description LIKE matches when pg_bigm+-- is not available. Single-statement file required for CREATE INDEX+-- CONCURRENTLY.+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_project_description_trgm+ ON project USING gin (LOWER(COALESCE(description, '')) gin_trgm_ops);