fix: fix schema migrations order

This commit is contained in:
Jan-Henrik 2026-03-06 22:36:36 +01:00
parent da95e90ba2
commit 43a1c71dd1

View file

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