-- 185_tradein_osm_poi_view.sql -- Issue #2045 (trade-in location-coef/POI, PR 1 of 2 — gendesign side only). -- Exposes osm_poi_ekb (82_osm_poi_ekb.sql) to tradein-postgres via the existing -- postgres_fdw bridge / tradein_fdw_reader role (100_tradein_fdw_role.sql). -- Mirrors v_tradein_cad_buildings: flat, minimal column slice + freshness filter, -- GRANT SELECT to the already-existing role (no new role / no user mapping here). -- -- Second PR (FDW foreign table + service in tradein-mvp) lands separately AFTER -- this migration is deployed on gendesign. -- -- Idempotent: CREATE OR REPLACE VIEW + repeatable GRANT. BEGIN; CREATE OR REPLACE VIEW v_tradein_osm_poi_ekb AS SELECT category, name, lat, lon FROM osm_poi_ekb WHERE last_osm_edit_date IS NULL OR last_osm_edit_date > now() - interval '2 years'; GRANT SELECT ON v_tradein_osm_poi_ekb TO tradein_fdw_reader; COMMENT ON VIEW v_tradein_osm_poi_ekb IS 'FDW source for tradein-mvp (postgres_fdw) location-coef/POI scoring (#2045). ' 'Flat 4-col EKB-only slice of osm_poi_ekb, filtered to POI edited within 2 years ' '(or with unknown edit date).'; COMMIT;