mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
Merge pull request #155 from Hestia-Homes/new-reporting
added uniqueness constraints to property details epc and spatial
This commit is contained in:
commit
f9ce0ea738
4 changed files with 5002 additions and 76 deletions
2
src/app/db/migrations/0140_keen_dreaming_celestial.sql
Normal file
2
src/app/db/migrations/0140_keen_dreaming_celestial.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
CREATE UNIQUE INDEX "uq_property_details_epc_property_portfolio" ON "property_details_epc" USING btree ("property_id","portfolio_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "uq_property_details_spatial_uprn" ON "property_details_spatial" USING btree ("uprn");
|
||||
4904
src/app/db/migrations/meta/0140_snapshot.json
Normal file
4904
src/app/db/migrations/meta/0140_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -981,6 +981,13 @@
|
|||
"when": 1766321608808,
|
||||
"tag": "0139_skinny_legion",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 140,
|
||||
"version": "7",
|
||||
"when": 1766389269465,
|
||||
"tag": "0140_keen_dreaming_celestial",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -150,83 +150,96 @@ export const FeatureRating: [string, ...string[]] = [
|
|||
|
||||
export const FeatureRatingNumeric: [number, ...number[]] = [5, 4, 3, 2, 1];
|
||||
|
||||
export const propertyDetailsEpc = pgTable("property_details_epc", {
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
propertyId: bigint("property_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => property.id),
|
||||
portfolioId: bigint("portfolio_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => portfolio.id),
|
||||
fullAddress: text("full_address"),
|
||||
// Date the EPC was lodged
|
||||
lodgementDate: timestamp("lodgement_date"),
|
||||
isExpired: boolean("is_expired"),
|
||||
totalFloorArea: real("total_floor_area"),
|
||||
walls: text("walls"),
|
||||
wallsRating: smallint("walls_rating"),
|
||||
roof: text("roof"),
|
||||
roofRating: smallint("roof_rating"),
|
||||
floor: text("floor"),
|
||||
floorRating: smallint("floor_rating"),
|
||||
windows: text("windows"),
|
||||
windowsRating: smallint("windows_rating"),
|
||||
heating: text("heating"),
|
||||
heatingRating: smallint("heating_rating"),
|
||||
heatingControls: text("heating_controls"),
|
||||
heatingControlsRating: smallint("heating_controls_rating"),
|
||||
hotWater: text("hot_water"),
|
||||
hotWaterRating: smallint("hot_water_rating"),
|
||||
lighting: text("lighting"),
|
||||
lightingRating: smallint("lighting_rating"),
|
||||
mainfuel: text("mainfuel"),
|
||||
ventilation: text("ventilation"),
|
||||
solarPv: real("solar_pv"),
|
||||
solarHotWater: boolean("solar_hot_water"),
|
||||
windTurbine: smallint("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"),
|
||||
currentEnergyDemand: real("current_energy_demand"),
|
||||
currentEnergyDemandHeatingHotwater: real(
|
||||
"current_energy_demand_heating_hotwater"
|
||||
),
|
||||
estimated: boolean("estimated").default(false),
|
||||
// We indicate if the property has an overwritten SAP 05 EPC. I.e. there is a valid EPC, however it's a SAP 05
|
||||
// EPC which isn't particularly useful. This value is defaulted to False
|
||||
sap05Overwritten: boolean("sap_05_overwritten").default(false),
|
||||
// When we've overwritten a SAP 05 EPC, we store the SAP 05 score and rating here for reference
|
||||
sap05Score: real("sap_05_score"),
|
||||
sap05EpcRating: epcEnum("sap_05_epc_rating"),
|
||||
// Include current estimates for energy bills, across the different types of energy
|
||||
// These predictions are based on the EPC predicted consumptions + current energy prices
|
||||
heatingEnergyCostCurrent: real("heating_cost_current"),
|
||||
hotWaterEnergyCostCurrent: real("hot_water_cost_current"),
|
||||
lightingEnergyCostCurrent: real("lighting_cost_current"),
|
||||
appliancesEnergyCostCurrent: real("appliances_cost_current"),
|
||||
gasStandingCharge: real("gas_standing_charge"),
|
||||
electricityStandingCharge: real("electricity_standing_charge"),
|
||||
});
|
||||
export const propertyDetailsEpc = pgTable(
|
||||
"property_details_epc",
|
||||
{
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
propertyId: bigint("property_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => property.id),
|
||||
portfolioId: bigint("portfolio_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => portfolio.id),
|
||||
fullAddress: text("full_address"),
|
||||
// Date the EPC was lodged
|
||||
lodgementDate: timestamp("lodgement_date"),
|
||||
isExpired: boolean("is_expired"),
|
||||
totalFloorArea: real("total_floor_area"),
|
||||
walls: text("walls"),
|
||||
wallsRating: smallint("walls_rating"),
|
||||
roof: text("roof"),
|
||||
roofRating: smallint("roof_rating"),
|
||||
floor: text("floor"),
|
||||
floorRating: smallint("floor_rating"),
|
||||
windows: text("windows"),
|
||||
windowsRating: smallint("windows_rating"),
|
||||
heating: text("heating"),
|
||||
heatingRating: smallint("heating_rating"),
|
||||
heatingControls: text("heating_controls"),
|
||||
heatingControlsRating: smallint("heating_controls_rating"),
|
||||
hotWater: text("hot_water"),
|
||||
hotWaterRating: smallint("hot_water_rating"),
|
||||
lighting: text("lighting"),
|
||||
lightingRating: smallint("lighting_rating"),
|
||||
mainfuel: text("mainfuel"),
|
||||
ventilation: text("ventilation"),
|
||||
solarPv: real("solar_pv"),
|
||||
solarHotWater: boolean("solar_hot_water"),
|
||||
windTurbine: smallint("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"),
|
||||
currentEnergyDemand: real("current_energy_demand"),
|
||||
currentEnergyDemandHeatingHotwater: real(
|
||||
"current_energy_demand_heating_hotwater"
|
||||
),
|
||||
estimated: boolean("estimated").default(false),
|
||||
// We indicate if the property has an overwritten SAP 05 EPC. I.e. there is a valid EPC, however it's a SAP 05
|
||||
// EPC which isn't particularly useful. This value is defaulted to False
|
||||
sap05Overwritten: boolean("sap_05_overwritten").default(false),
|
||||
// When we've overwritten a SAP 05 EPC, we store the SAP 05 score and rating here for reference
|
||||
sap05Score: real("sap_05_score"),
|
||||
sap05EpcRating: epcEnum("sap_05_epc_rating"),
|
||||
// Include current estimates for energy bills, across the different types of energy
|
||||
// These predictions are based on the EPC predicted consumptions + current energy prices
|
||||
heatingEnergyCostCurrent: real("heating_cost_current"),
|
||||
hotWaterEnergyCostCurrent: real("hot_water_cost_current"),
|
||||
lightingEnergyCostCurrent: real("lighting_cost_current"),
|
||||
appliancesEnergyCostCurrent: real("appliances_cost_current"),
|
||||
gasStandingCharge: real("gas_standing_charge"),
|
||||
electricityStandingCharge: real("electricity_standing_charge"),
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex("uq_property_details_epc_property_portfolio").on(
|
||||
table.propertyId,
|
||||
table.portfolioId
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
export const propertyDetailsSpatial = pgTable("property_details_spatial", {
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
uprn: bigint("uprn", { mode: "bigint" }),
|
||||
xCoordinate: real("x_coordinate"),
|
||||
yCoordinate: real("y_coordinate"),
|
||||
latitude: real("latitude"),
|
||||
longitude: real("longitude"),
|
||||
conservationStatus: boolean("conservation_status"),
|
||||
isListedBuilding: boolean("is_listed_building"),
|
||||
isHeritageBuilding: boolean("is_heritage_building"),
|
||||
});
|
||||
export const propertyDetailsSpatial = pgTable(
|
||||
"property_details_spatial",
|
||||
{
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
uprn: bigint("uprn", { mode: "bigint" }),
|
||||
xCoordinate: real("x_coordinate"),
|
||||
yCoordinate: real("y_coordinate"),
|
||||
latitude: real("latitude"),
|
||||
longitude: real("longitude"),
|
||||
conservationStatus: boolean("conservation_status"),
|
||||
isListedBuilding: boolean("is_listed_building"),
|
||||
isHeritageBuilding: boolean("is_heritage_building"),
|
||||
},
|
||||
(table) => [uniqueIndex("uq_property_details_spatial_uprn").on(table.uprn)]
|
||||
);
|
||||
|
||||
export const propertyDetailsMeter = pgTable("property_details_meter", {
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue