diff --git a/data/sql/92_cad_bulk_layers.sql b/data/sql/92_cad_bulk_layers.sql index cb5a8b83..82183634 100644 --- a/data/sql/92_cad_bulk_layers.sql +++ b/data/sql/92_cad_bulk_layers.sql @@ -503,6 +503,12 @@ 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. + 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_new_pkey RENAME TO cad_buildings_pkey; -- Note: ALTER INDEX RENAME on a PK index also renames the constraint