diff --git a/infrastructure/scripts/poi-import.sh b/infrastructure/scripts/poi-import.sh index cfee4e5..1ff9afe 100755 --- a/infrastructure/scripts/poi-import.sh +++ b/infrastructure/scripts/poi-import.sh @@ -151,7 +151,7 @@ ALTER TABLE planner.pois_staging RENAME TO pois; -- `db:push` sees no drift. pois_old still holds the old canonical names until -- it's dropped, so free them first. DROP TABLE planner.pois_old; -ALTER TABLE planner.pois RENAME CONSTRAINT pois_staging_pkey TO pois_osm_type_osm_id_category_pk; +ALTER TABLE planner.pois RENAME CONSTRAINT pois_staging_pkey TO pois_pkey; ALTER INDEX planner.pois_staging_geom_idx RENAME TO pois_geom_idx; ALTER INDEX planner.pois_staging_category_idx RENAME TO pois_category_idx; COMMIT; diff --git a/packages/db/src/schema/planner.ts b/packages/db/src/schema/planner.ts index 6c52bc3..48e7713 100644 --- a/packages/db/src/schema/planner.ts +++ b/packages/db/src/schema/planner.ts @@ -52,7 +52,9 @@ export const pois = plannerSchema.table("pois", { tags: jsonb("tags").$type>().notNull(), importedAt: timestamp("imported_at", { withTimezone: true }).notNull().defaultNow(), }, (t) => ({ - pk: primaryKey({ columns: [t.osmType, t.osmId, t.category] }), + // Named explicitly so the import job's atomic swap can rename the staging + // table's PK to this exact name — keeping `db:push` drift-free post-swap. + pk: primaryKey({ name: "pois_pkey", columns: [t.osmType, t.osmId, t.category] }), // GiST spatial index for the bbox intersection in the serving query. geomIdx: index("pois_geom_idx").using("gist", t.geom), // btree on category so `category = ANY($cats)` is index-driven.