-- ekb_districts_geom — PostGIS-полигоны 8 районов Екатеринбурга из OSM.
-- Загрузка через scripts/56_fetch_ekb_districts.py.
-- Используется для spatial-join (lat,lon) → district в:
--   1. backfill domrf_kn_objects.district_name
--   2. recommend_mix (_velocity_baseline / _elasticity_coef / comparable / competitors)
-- Idempotent.

CREATE EXTENSION IF NOT EXISTS postgis;

CREATE TABLE IF NOT EXISTS ekb_districts_geom (
    district_name TEXT PRIMARY KEY REFERENCES ekb_districts(district_name),
    geom geometry(MultiPolygon, 4326) NOT NULL,
    osm_id BIGINT,
    fetched_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_ekb_districts_geom_geom
    ON ekb_districts_geom USING GIST (geom);
