diff --git a/infra/schema.sql b/infra/schema.sql index a37dcc8..c4be426 100644 --- a/infra/schema.sql +++ b/infra/schema.sql @@ -24,12 +24,6 @@ ALTER TABLE cities ADD COLUMN IF NOT EXISTS resolution_m INTEGER NOT NULL DEFAUL ALTER TABLE cities ADD COLUMN IF NOT EXISTS boundary geometry(MultiPolygon, 4326); ALTER TABLE cities ADD COLUMN IF NOT EXISTS refresh_iter SMALLINT NOT NULL DEFAULT 0; --- Migration: rename 'fifteen' mode to 'cyclist' and update CHECK constraint -UPDATE grid_scores SET travel_mode = 'cyclist' WHERE travel_mode = 'fifteen'; -ALTER TABLE grid_scores DROP CONSTRAINT IF EXISTS grid_scores_travel_mode_check; -ALTER TABLE grid_scores ADD CONSTRAINT grid_scores_travel_mode_check - CHECK (travel_mode IN ('walking','cycling','driving','transit','cyclist','cycling_walk','transit_walk')); - CREATE INDEX IF NOT EXISTS idx_cities_bbox ON cities USING GIST (bbox); CREATE INDEX IF NOT EXISTS idx_cities_boundary ON cities USING GIST (boundary); @@ -101,6 +95,16 @@ ALTER TABLE grid_scores ADD COLUMN IF NOT EXISTS profile TEXT NOT NULL DEFAULT ' CREATE INDEX IF NOT EXISTS idx_grid_scores_lookup ON grid_scores (grid_point_id, travel_mode, threshold_min, profile); +-- Migration: rename 'fifteen' mode to 'cyclist' and update CHECK constraint +DO $$ BEGIN + IF EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'grid_scores') THEN + UPDATE grid_scores SET travel_mode = 'cyclist' WHERE travel_mode = 'fifteen'; + END IF; +END $$; +ALTER TABLE grid_scores DROP CONSTRAINT IF EXISTS grid_scores_travel_mode_check; +ALTER TABLE grid_scores ADD CONSTRAINT grid_scores_travel_mode_check + CHECK (travel_mode IN ('walking','cycling','driving','transit','cyclist','cycling_walk','transit_walk')); + -- ─── Nearest POIs per subcategory per grid point ───────────────────────────── -- Populated by compute-routing / compute-transit jobs. Stores up to K nearest -- POIs per (grid_point, category, subcategory, travel_mode) so that the scoring