feat(db): supply_layers store + latest view (#950 PR B) #1003

Merged
Light1YT merged 1 commit from feat/950b-supply-layers-schema into main 2026-06-02 20:21:05 +00:00

1 commit

Author SHA1 Message Date
37b4330eae feat(db): supply_layers store + latest view (#950 PR B)
Durable 3-layer supply store for Site Finder v2 EPIC 6 (open/hidden/future)
at district grain (+ optional per-ЖК). TABLE not MV because Layer3 holds
non-derivable rows (граддок stubs #956, manual insider) that the worker
recompute must not clobber; Layer1/2 are UPSERT-ed by the #950 Step 5 worker.

UNIQUE NULLS NOT DISTINCT on (layer, district_name, complex_id, obj_class,
source, snapshot_date) so region-wide NULL-grain rows dedupe and ON CONFLICT
matches (PG16). CHECKs on layer/confidence/source fail loud; FK to
complexes(id) ON DELETE SET NULL. v_supply_layers_latest returns the newest
snapshot per logical key (deterministic tiebreak). Idempotent: guarded
DO-blocks for UNIQUE+FK, IF NOT EXISTS elsewhere. Dry-run-verified on a
PG16.4/PostGIS3.4 container (re-applied 3x, behavioral tests pass).
2026-06-03 01:20:04 +05:00