poi-index: name pois PK explicitly (pois_pkey) for drift-free swap

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-07-12 22:55:49 +02:00
parent 96de8831cf
commit b1aa687c51
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
2 changed files with 4 additions and 2 deletions

View file

@ -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;

View file

@ -52,7 +52,9 @@ export const pois = plannerSchema.table("pois", {
tags: jsonb("tags").$type<Record<string, string>>().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.