fix(db): retire legacy cad_buildings_pkey — fix migration 92 hotfix (#168) #173

Merged
lekss361 merged 1 commit from fix/cadastre-schema-pkey-rename into main 2026-05-15 10:59:53 +00:00

1 commit

Author SHA1 Message Date
lekss361
e2d1ce3679 fix(db): retire legacy cad_buildings_pkey before rename — fix migration 92 (#168 hotfix)
Migration 92_cad_bulk_layers.sql fails on deploy with:
  ERROR: relation "cad_buildings_pkey" already exists
  CONTEXT: ALTER INDEX cad_buildings_new_pkey RENAME TO cad_buildings_pkey

Root cause: K.1 renamed cad_buildings → cad_buildings_old_apr26, but PG
does NOT auto-rename the backing PK index on table rename. The legacy
cad_buildings_pkey index is still attached to cad_buildings_old_apr26.
K.3 then tries to rename cad_buildings_new_pkey to the same name → collision.

Fix: add an explicit `ALTER INDEX IF EXISTS cad_buildings_pkey RENAME TO
cad_buildings_old_apr26_pkey` BEFORE the new rename. Idempotent (IF EXISTS).

Migration 92 was rolled back in last 3 deploy attempts (not in
_schema_migrations), so this edit will re-apply cleanly on next deploy.
2026-05-15 13:51:24 +03:00