mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
created new tables for epc data store and installed measures
This commit is contained in:
parent
10beee1345
commit
40be91f482
5 changed files with 4776 additions and 0 deletions
17
src/app/db/migrations/0128_thin_wiccan.sql
Normal file
17
src/app/db/migrations/0128_thin_wiccan.sql
Normal 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
|
||||
);
|
||||
4690
src/app/db/migrations/meta/0128_snapshot.json
Normal file
4690
src/app/db/migrations/meta/0128_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -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
44
src/app/db/schema/epc.ts
Normal 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(),
|
||||
});
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue