fix(db): retire all legacy cad_buildings indexes — hotfix2 (#168) #174

Merged
lekss361 merged 1 commit from fix/cadastre-schema-all-pkey-rename into main 2026-05-15 11:09:41 +00:00

View file

@ -503,13 +503,18 @@ BEGIN
WHERE table_schema = 'public' AND table_name = 'cad_buildings' WHERE table_schema = 'public' AND table_name = 'cad_buildings'
) THEN ) THEN
ALTER TABLE cad_buildings_new RENAME TO cad_buildings; ALTER TABLE cad_buildings_new RENAME TO cad_buildings;
-- First, retire the legacy PK index name that's still attached to -- First, retire ALL legacy index names that are still attached to
-- cad_buildings_old_apr26 (PG does NOT auto-rename PK indexes on -- cad_buildings_old_apr26 — PG does NOT auto-rename indexes on
-- table rename — pre-K.1 backup left cad_buildings_pkey behind). -- table rename, so pre-K.1 backup left all 6 names occupied.
-- Without this rename, the next line collides with the existing -- Without these renames, the _new → unsuffixed renames below collide
-- index name → 'relation already exists' → tx rollback. -- → 'relation already exists' → tx rollback.
ALTER INDEX IF EXISTS cad_buildings_pkey RENAME TO cad_buildings_old_apr26_pkey; ALTER INDEX IF EXISTS cad_buildings_pkey RENAME TO cad_buildings_old_apr26_pkey;
-- Rename indexes to drop the _new suffix ALTER INDEX IF EXISTS cad_buildings_geom_gist RENAME TO cad_buildings_old_apr26_geom_gist;
ALTER INDEX IF EXISTS cad_buildings_quarter_idx RENAME TO cad_buildings_old_apr26_quarter_idx;
ALTER INDEX IF EXISTS cad_buildings_objdoc_idx RENAME TO cad_buildings_old_apr26_objdoc_idx;
ALTER INDEX IF EXISTS cad_buildings_complex_idx RENAME TO cad_buildings_old_apr26_complex_idx;
ALTER INDEX IF EXISTS cad_buildings_purpose_idx RENAME TO cad_buildings_old_apr26_purpose_idx;
-- Now rename _new → unsuffixed names safely
ALTER INDEX IF EXISTS cad_buildings_new_pkey RENAME TO cad_buildings_pkey; ALTER INDEX IF EXISTS cad_buildings_new_pkey RENAME TO cad_buildings_pkey;
-- Note: ALTER INDEX RENAME on a PK index also renames the constraint -- Note: ALTER INDEX RENAME on a PK index also renames the constraint
-- automatically in PG 16. No separate RENAME CONSTRAINT needed. -- automatically in PG 16. No separate RENAME CONSTRAINT needed.