Files
multica/server/migrations/171_drop_legacy_label_namespace_index.down.sql
Bohan Jiang 8567ebffd9 fix(migrations): rebuild legacy label index CONCURRENTLY on rollback (MUL-4479) (#5357)
The 162_resource_labels down migration recreated issue_label_workspace_name_lower_idx
with a plain CREATE UNIQUE INDEX, which takes a blocking lock on the existing
issue_label table during a rollback to v0.3.43 and violates the online-migration
rule that every CREATE INDEX must be CONCURRENTLY.

CREATE INDEX CONCURRENTLY cannot run in a transaction or a multi-command migration,
so the rebuild is split out of 162.down:
- 171.down now rebuilds the legacy index as a single CREATE UNIQUE INDEX CONCURRENTLY
  (the natural inverse of 171.up, which drops it).
- 174 (new, no-op up) deletes the agent/skill label rows in its down so they are gone
  before 171.down rebuilds the workspace-wide unique index. Down migrations apply
  high->low, so 174.down -> 171.down -> 162.down runs in the required order.
- 162.down keeps only the transaction-safe structural teardown.

Validated on an isolated Postgres: full up->down->up chain with a colliding
issue/agent label pair; the concurrent rebuild succeeds after the rows are deleted,
restores the valid pre-162 unique index, and a negative control (rebuild before the
delete) fails on the exact collision.

Co-authored-by: J <j@multica.ai>
Co-authored-by: multica-agent <github@multica.ai>
2026-07-13 19:31:27 +08:00

11 lines
616 B
SQL

-- Inverse of 171.up, which drops the pre-162 workspace-wide unique name
-- index. Recreated as a single CREATE INDEX CONCURRENTLY statement so the
-- rollback stays online-safe (it cannot be combined with other statements
-- or run inside a transaction block).
--
-- The agent/skill rows that would violate this workspace-wide uniqueness are
-- removed earlier in the down chain by 174.down (down migrations apply
-- high->low), so only issue rows remain when this index is rebuilt.
CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS issue_label_workspace_name_lower_idx
ON issue_label (workspace_id, LOWER(name));