Added property tables schemas

This commit is contained in:
Khalim Conn-Kowlessar 2023-07-31 14:47:14 +01:00
parent fbefb31dd5
commit 25a09acb32
2 changed files with 114 additions and 1 deletions

View file

@ -1,3 +1,16 @@
import {
serial,
text,
timestamp,
pgTable,
real,
pgEnum,
integer,
boolean,
} from "drizzle-orm/pg-core";
import { portfolio } from "./portfolio";
import { InferModel } from "drizzle-orm";
// This is a placeholder for the property schema
export interface PropertyMeta {
id: number;
@ -46,3 +59,103 @@ export interface ConditionReportData {
heatingDemand: GeneralFeature[];
yearBuilt: string;
}
export const PropertyStatus: [string, ...string[]] = [
"LOADING",
"READY",
"ERROR",
];
export const Epc: [string, ...string[]] = ["A", "B", "C", "D", "E", "F", "G"];
export const propertyStatusEnum = pgEnum("property_status", PropertyStatus);
export const epcEnum = pgEnum("epc", Epc);
export const property = pgTable("property", {
id: serial("id").primaryKey(),
portfolioId: integer("portfolio_id")
.notNull()
.references(() => portfolio.id),
status: propertyStatusEnum("status").notNull(),
uprn: integer("uprn"),
address: text("address"),
postcode: text("postcode"),
hasPreConditionReport: boolean("has_pre_condition_report"),
hasRecommendations: boolean("has_recommendations"),
createdAt: timestamp("created_at").notNull(),
updatedAt: timestamp("updated_at").notNull(),
propertyType: text("property_type"),
builtForm: text("built_form"),
localAuthority: text("local_authority"),
constituency: text("constituency"),
numberOfRooms: integer("number_of_rooms"),
yearBuilt: text("year_built"),
tenure: text("tenure"),
currentEpcRating: epcEnum("current_epc_rating"),
currentSapPoints: real("current_sap_points"),
});
export const FeatureRating: [string, ...string[]] = [
"Very good",
"Good",
"Poor",
"Very poor",
"N/A",
];
export const featureRatingEnum = pgEnum("feature_rating", FeatureRating);
export const propertyDetailsEpc = pgTable("property_details_epc", {
id: serial("id").primaryKey(),
propertyId: integer("property_id")
.notNull()
.references(() => property.id),
portfolioId: integer("portfolio_id")
.notNull()
.references(() => portfolio.id),
fullAddress: text("full_address"),
totalFloorArea: real("total_floor_area"),
walls: text("walls"),
wallsRating: featureRatingEnum("walls_rating"),
roof: text("roof"),
roofRating: featureRatingEnum("roof_rating"),
floor: text("floor"),
floorRating: featureRatingEnum("floor_rating"),
windows: text("windows"),
windowsRating: featureRatingEnum("windows_rating"),
heating: text("heating"),
heatingRating: featureRatingEnum("heating_rating"),
heatingContols: text("heating_contols"),
heatingContolsRating: featureRatingEnum("heating_contols_rating"),
hotWater: text("hot_water"),
hotWaterRating: featureRatingEnum("hot_water_rating"),
lighting: text("lighting"),
lightingRating: featureRatingEnum("lighting_rating"),
ventilation: text("ventilation"),
solarPv: text("solar_pv"),
solarHotWater: text("solar_hot_water"),
windTurbine: text("wind_turbine"),
floorHeight: real("floor_height"),
numberHeatedRooms: integer("number_heated_rooms"),
heatLossCorridor: boolean("heat_loss_corridor"),
unheatedCorridorLength: real("unheated_corridor_length"),
numberOpenFireplaces: integer("number_of_open_fireplaces"),
numberExtensions: integer("number_of_extensions"),
numberStoreys: integer("number_of_storeys"),
mainsGas: boolean("mains_gas"),
energyTariff: text("energy_tariff"),
primaryEnergyConsumption: real("primary_energy_consumption"),
co2Emissions: real("co2_emissions"),
});
export const propertyDetailsMeter = pgTable("property_details_meter", {
id: serial("id").primaryKey(),
uprn: integer("uprn").notNull(),
energySupplier: text("energy_supplier"),
gasSupplier: text("gas_supplier"),
meterReadingTotal: real("meter_reading_total"),
meterReadingElectricity: real("meter_reading_electricity"),
meterReadingGas: real("meter_reading_gas"),
});
// TODO: We'll need a property details buildings materials for verisk data?

View file

@ -10,7 +10,7 @@ import {
UserGroupIcon,
} from "@heroicons/react/24/solid";
export default function BuildingPassportHome() {
export default async function BuildingPassportHome() {
const propertyMeta: PropertyMeta = {
id: 1,
address: "123 Fake Street",