created new tables for epc data store and installed measures

This commit is contained in:
Khalim Conn-Kowlessar 2025-11-25 13:35:27 +00:00
parent 10beee1345
commit 40be91f482
5 changed files with 4776 additions and 0 deletions

View file

@ -0,0 +1,17 @@
CREATE TABLE "epc_store" (
"id" serial PRIMARY KEY NOT NULL,
"uprn" bigint,
"epc_api_created_at" timestamp DEFAULT now() NOT NULL,
"epc_api" jsonb NOT NULL,
"epc_page_created_at" timestamp DEFAULT now() NOT NULL,
"epc_page" text NOT NULL,
"epc_page_rrn" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "property_installed_measures" (
"id" bigserial PRIMARY KEY NOT NULL,
"uprn" bigint NOT NULL,
"measure_type" "type" NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"installed_at" timestamp DEFAULT now() NOT NULL
);

File diff suppressed because it is too large Load diff

View file

@ -897,6 +897,13 @@
"when": 1763119819059,
"tag": "0127_acoustic_sleepwalker",
"breakpoints": true
},
{
"idx": 128,
"version": "7",
"when": 1764072359053,
"tag": "0128_thin_wiccan",
"breakpoints": true
}
]
}

44
src/app/db/schema/epc.ts Normal file
View file

@ -0,0 +1,44 @@
import {
pgTable,
serial,
text,
jsonb,
timestamp,
bigint,
} from "drizzle-orm/pg-core";
// This table stores postcode search results from the OS Places API
// for re-use and caching purposes. The data is stored in jsonb format, to
// allow for fast queries and flexibility with the API response structure.
export interface OSPlacesHeader {
totalresults?: number;
offset?: number;
maxresults?: number;
[k: string]: any;
}
export interface EpcApiResponse {
header?: OSPlacesHeader;
rows?: Record<string, any>;
}
export const epcStore = pgTable("epc_store", {
id: serial("id").primaryKey(),
uprn: bigint("uprn", { mode: "bigint" }),
// Timestamp for when the EPC API entry was first stored
epcApiCreatedAt: timestamp("epc_api_created_at").defaultNow().notNull(),
// EPC API response for the UPRN
epcApi: jsonb("epc_api").$type<EpcApiResponse>().notNull(),
// Timestamp for when the EPC page was stored
epcPageCreatedAt: timestamp("epc_page_created_at").defaultNow().notNull(),
// HTML content of the EPC page
epcPage: text("epc_page").notNull(),
// RRN of the EPC page
epcPageRrn: text("epc_page_rrn").notNull(),
});

View file

@ -12,6 +12,7 @@ import {
} from "drizzle-orm/pg-core";
import { portfolio, PortfolioStatus } from "./portfolio";
import { InferModel } from "drizzle-orm";
import { materialTypeEnum } from "./materials";
// This is a placeholder for the property schema
export interface PropertyMeta {
@ -241,6 +242,23 @@ export const nonIntrusiveSurveyNotes = pgTable("non_intrusive_survey_notes", {
note: text("note").notNull(),
});
// This model is a record of the measures that have already been installed for a property
// This is considered as supplementary daa and stored against the UPRN
// RecommendationType is the
export const propertyInstalledMeasures = pgTable(
"property_installed_measures",
{
id: bigserial("id", { mode: "bigint" }).primaryKey(),
uprn: bigint("uprn", { mode: "bigint" }).notNull(),
// The material types define the list of measures we should expect
measureType: materialTypeEnum("measure_type").notNull(),
// Record of when this measure was inserted into the db
createdAt: timestamp("created_at").notNull().defaultNow(),
// Record of when this measure was actually installed
installedAt: timestamp("installed_at").notNull().defaultNow(),
}
);
export type Property = InferModel<typeof property, "select">;
export type PropertyDetailsEpc = InferModel<
typeof propertyDetailsEpc,