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
Owner

Site Finder v2 / EPIC 6 — #950 Step 2 / PR B. Pure schema, без LLM. Часть #944.

Долговременная таблица supply_layers — единый склад 3 слоёв (open/hidden/future) на district-grain (+ optional per-ЖК) + read-view v_supply_layers_latest. TABLE, не MV — Layer3 держит невыводимые запросом строки (граддок-stubs #956, ручной insider), которые пересчёт воркера не должен затирать; Layer1/2 UPSERT-ятся воркером (#950 Step 5).

  • UNIQUE NULLS NOT DISTINCT (layer, district_name, complex_id, obj_class, source, snapshot_date) (PG16) — region-wide NULL-grain строки дедуплицируются + ON CONFLICT матчит.
  • CHECK на layer/confidence/source (fail-loud); FK complexes(id) ON DELETE SET NULL.
  • v_supply_layers_latest — свежий снапшот на ключ, детерминир. tiebreak.
  • Idempotent: guarded DO-блоки для UNIQUE+FK, IF NOT EXISTS остальное.

Dry-run-verified на реальном PG16.4/PostGIS3.4 контейнере (прод-образ): re-apply 3x чисто, ON CONFLICT на NULL-district обновляет (не дублит), CHECK/FK/latest-view — все behavioral-тесты прошли. Self-review orchestrator OK. Refs #950

**Site Finder v2 / EPIC 6 — #950 Step 2 / PR B.** Pure schema, без LLM. Часть #944. Долговременная таблица `supply_layers` — единый склад 3 слоёв (open/hidden/future) на district-grain (+ optional per-ЖК) + read-view `v_supply_layers_latest`. **TABLE, не MV** — Layer3 держит невыводимые запросом строки (граддок-stubs #956, ручной insider), которые пересчёт воркера не должен затирать; Layer1/2 UPSERT-ятся воркером (#950 Step 5). - `UNIQUE NULLS NOT DISTINCT (layer, district_name, complex_id, obj_class, source, snapshot_date)` (PG16) — region-wide NULL-grain строки дедуплицируются + ON CONFLICT матчит. - CHECK на layer/confidence/source (fail-loud); FK `complexes(id) ON DELETE SET NULL`. - `v_supply_layers_latest` — свежий снапшот на ключ, детерминир. tiebreak. - Idempotent: guarded DO-блоки для UNIQUE+FK, IF NOT EXISTS остальное. **Dry-run-verified на реальном PG16.4/PostGIS3.4 контейнере** (прод-образ): re-apply 3x чисто, ON CONFLICT на NULL-district обновляет (не дублит), CHECK/FK/latest-view — все behavioral-тесты прошли. Self-review orchestrator OK. Refs #950
Light1YT added 1 commit 2026-06-02 20:21:03 +00:00
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).
Light1YT merged commit 33ecbda689 into main 2026-06-02 20:21:05 +00:00
Light1YT deleted branch feat/950b-supply-layers-schema 2026-06-02 20:21:05 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#1003
No description provided.