mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
feat(db): add epc_property.source for predicted-EPC slot (ADR-0031)
Adds a `source` discriminator to `epc_property` so a property can hold a lodged and a predicted EPC at the same time, per the EPC Prediction production-wiring branch in the Model repo (docs/MIGRATION_NOTE_predicted_epc_source.md). - `source` text NOT NULL default 'lodged' — backfills every existing row as a real lodged EPC. - Unique index becomes (property_id, portfolio_id, source) so lodged + predicted rows can coexist for the same property/portfolio. - New (property_id, source) index — lodged/predicted reads filter on both. Allowed values: 'lodged' | 'predicted'. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7feec70c98
commit
ae74133575
4 changed files with 10992 additions and 0 deletions
4
src/app/db/migrations/0234_old_rachel_grey.sql
Normal file
4
src/app/db/migrations/0234_old_rachel_grey.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
DROP INDEX "uq_epc_property_property_portfolio";--> statement-breakpoint
|
||||
ALTER TABLE "epc_property" ADD COLUMN "source" text DEFAULT 'lodged' NOT NULL;--> statement-breakpoint
|
||||
CREATE INDEX "ix_epc_property_property_source" ON "epc_property" USING btree ("property_id","source");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "uq_epc_property_property_portfolio" ON "epc_property" USING btree ("property_id","portfolio_id","source");
|
||||
10966
src/app/db/migrations/meta/0234_snapshot.json
Normal file
10966
src/app/db/migrations/meta/0234_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1632,6 +1632,13 @@
|
|||
"when": 1781513971818,
|
||||
"tag": "0233_abnormal_george_stacy",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 234,
|
||||
"version": "7",
|
||||
"when": 1781617412914,
|
||||
"tag": "0234_old_rachel_grey",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import {
|
|||
smallint,
|
||||
bigint,
|
||||
uniqueIndex,
|
||||
index,
|
||||
jsonb,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { portfolio, PortfolioStatus } from "./portfolio";
|
||||
|
|
@ -428,6 +429,12 @@ export const epcProperty = pgTable(
|
|||
.unique()
|
||||
.references(() => uploadedFiles.id),
|
||||
|
||||
// Provenance of this EPC picture: "lodged" (a real public/landlord EPC) or
|
||||
// "predicted" (EPC Prediction gap-fill, ADR-0031 in the Model repo). A
|
||||
// property may hold one of each, so reads filter on it. Defaults to "lodged"
|
||||
// — every existing row is a real lodged EPC.
|
||||
source: text("source").notNull().default("lodged"),
|
||||
|
||||
// Identity / admin
|
||||
uprn: bigint("uprn", { mode: "bigint" }),
|
||||
uprnSource: text("uprn_source"),
|
||||
|
|
@ -577,9 +584,17 @@ export const epcProperty = pgTable(
|
|||
ventilationMechanicalVentilationKind: text("ventilation_mechanical_ventilation_kind"),
|
||||
},
|
||||
(table) => [
|
||||
// A property may now hold one "lodged" and one "predicted" EPC row per
|
||||
// portfolio (ADR-0031), so `source` is part of the uniqueness key.
|
||||
uniqueIndex("uq_epc_property_property_portfolio").on(
|
||||
table.propertyId,
|
||||
table.portfolioId,
|
||||
table.source,
|
||||
),
|
||||
// Every lodged/predicted read filters on (property_id, source).
|
||||
index("ix_epc_property_property_source").on(
|
||||
table.propertyId,
|
||||
table.source,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue