Merge pull request #321 from Hestia-Homes/feature/epc-prediction-source-column

feat(db): add epc_property.source for predicted-EPC slot (ADR-0031)
This commit is contained in:
Jun-te Kim 2026-06-16 14:51:07 +01:00 committed by GitHub
commit e606006e6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10992 additions and 0 deletions

View 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");

File diff suppressed because it is too large Load diff

View file

@ -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
}
]
}

View file

@ -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,
),
],
);