From ac18ef32f9b684b8438518b1f5005c1d04b3d3fc Mon Sep 17 00:00:00 2001 From: lekss361 Date: Fri, 15 May 2026 14:05:23 +0300 Subject: [PATCH] fix(db): retire ALL legacy cad_buildings index names before rename (#168 hotfix2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #173 fixed cad_buildings_pkey but missed 5 other indexes. Same root cause: PG does NOT auto-rename indexes on table rename → all 6 backing indexes remain on cad_buildings_old_apr26 with original names. Add 5 more `ALTER INDEX IF EXISTS ... RENAME TO ..._old_apr26_*` statements for: geom_gist, quarter_idx, objdoc_idx, complex_idx, purpose_idx. Migration 92 still NOT in _schema_migrations (4× rollback now). Next deploy will re-apply cleanly. --- data/sql/92_cad_bulk_layers.sql | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/data/sql/92_cad_bulk_layers.sql b/data/sql/92_cad_bulk_layers.sql index 82183634..e63d51e4 100644 --- a/data/sql/92_cad_bulk_layers.sql +++ b/data/sql/92_cad_bulk_layers.sql @@ -503,13 +503,18 @@ BEGIN WHERE table_schema = 'public' AND table_name = 'cad_buildings' ) THEN ALTER TABLE cad_buildings_new RENAME TO cad_buildings; - -- First, retire the legacy PK index name that's still attached to - -- cad_buildings_old_apr26 (PG does NOT auto-rename PK indexes on - -- table rename — pre-K.1 backup left cad_buildings_pkey behind). - -- Without this rename, the next line collides with the existing - -- index name → 'relation already exists' → tx rollback. + -- First, retire ALL legacy index names that are still attached to + -- cad_buildings_old_apr26 — PG does NOT auto-rename indexes on + -- table rename, so pre-K.1 backup left all 6 names occupied. + -- Without these renames, the _new → unsuffixed renames below collide + -- → 'relation already exists' → tx rollback. 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; -- Note: ALTER INDEX RENAME on a PK index also renames the constraint -- automatically in PG 16. No separate RENAME CONSTRAINT needed. -- 2.45.3