added new fields to db

This commit is contained in:
Khalim Conn-Kowlessar 2026-03-18 12:53:26 +00:00
parent d24c2a191a
commit 1165de9fe9
4 changed files with 5765 additions and 15 deletions

View file

@ -0,0 +1,5 @@
ALTER TABLE "property" ADD COLUMN "lodged_sap_points" real;--> statement-breakpoint
ALTER TABLE "property" ADD COLUMN "lodged_epc_rating" "epc";--> statement-breakpoint
ALTER TABLE "property_details_epc" ADD COLUMN "lodged_co2_emissions" real;--> statement-breakpoint
ALTER TABLE "property_details_epc" ADD COLUMN "lodged_heat_demand" real;--> statement-breakpoint
ALTER TABLE "property_details_epc" ADD COLUMN "has_been_remodelled" boolean DEFAULT false;

File diff suppressed because it is too large Load diff

View file

@ -1093,6 +1093,13 @@
"when": 1772637615885,
"tag": "0155_calm_hydra",
"breakpoints": true
},
{
"idx": 156,
"version": "7",
"when": 1773838366481,
"tag": "0156_long_kitty_pryde",
"breakpoints": true
}
]
}

View file

@ -88,7 +88,7 @@ export const Epc: [string, ...string[]] = ["A", "B", "C", "D", "E", "F", "G"];
export const propertyCreationStatusEnum = pgEnum(
"creation_status",
PropertyCreationStatus
PropertyCreationStatus,
);
export const epcEnum = pgEnum("epc", Epc);
export const propertyStatusEnum = pgEnum("status", PortfolioStatus);
@ -137,18 +137,22 @@ export const property = pgTable(
// 1) The number of points we've adjusted by
// 2) a flag to indicate whether the SAP points have been adjusted, for easily filtering
installedMeasuresSapPointAdjustment: real(
"installed_measures_sap_point_adjustment"
"installed_measures_sap_point_adjustment",
),
isSapPointsAdjustedForInstalledMeasures: boolean(
"is_sap_points_adjusted_for_installed_measures"
"is_sap_points_adjusted_for_installed_measures",
).default(false),
// To be deprecated
originalSapPoints: real("original_sap_points"),
// lodged data
lodgedSapPoints: real("lodged_sap_points"),
lodgedEpcRating: epcEnum("lodged_epc_rating"),
},
(table) => [
uniqueIndex("uq_property_portfolio_uprn")
.on(table.portfolioId, table.uprn)
.where(sql`${table.uprn} IS NOT NULL`),
]
],
);
export const FeatureRating: [string, ...string[]] = [
@ -212,7 +216,7 @@ export const propertyDetailsEpc = pgTable(
// Bad naming but currentEnergyDemand is the current kwh consumption - needs to be renamed
currentEnergyDemand: real("current_energy_demand"),
currentEnergyDemandHeatingHotwater: real(
"current_energy_demand_heating_hotwater"
"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
@ -236,36 +240,42 @@ export const propertyDetailsEpc = pgTable(
// 3) a flag to indicate whether the values have been adjusted, for easily filtering
// original values - we don't need bills because we don't actually adjust any of the originals we just subtract adjustments from current values
// TODO - deprecate
originalCo2Emissions: real("original_co2_emissions"),
originalPrimaryEnergyConsumption: real(
"original_primary_energy_consumption"
"original_primary_energy_consumption",
),
originalCurrentEnergyDemand: real("original_current_energy_demand"),
originalCurrentEnergyDemandHeatingHotwater: real(
"original_current_energy_demand_heating_hotwater"
"original_current_energy_demand_heating_hotwater",
),
// adjustment quantities
// adjustment quantities - TODO: deprecate
installedMeasuresCo2Adjustment: real("installed_measures_co2_adjustment"),
installedMeasuresEnergyDemandAdjustment: real(
"installed_measures_energy_demand_adjustment"
"installed_measures_energy_demand_adjustment",
),
installedMeasuresTotalEnergyBillAdjustment: real(
"installed_measures_total_energy_bill_adjustment"
"installed_measures_total_energy_bill_adjustment",
),
installedMeasuresHeatDemandAdjustment: real(
"installed_measures_heat_demand_adjustment"
"installed_measures_heat_demand_adjustment",
),
isEpcAdjustedForInstalledMeasures: boolean(
"is_epc_adjusted_for_installed_measures"
"is_epc_adjusted_for_installed_measures",
).default(false),
// Lodged values
lodgedCo2Emissions: real("lodged_co2_emissions"),
lodgedHeatDemand: real("lodged_heat_demand"),
hasBeenRemodelled: boolean("has_been_remodelled").default(false),
},
(table) => [
uniqueIndex("uq_property_details_epc_property_portfolio").on(
table.propertyId,
table.portfolioId
table.portfolioId,
),
]
],
);
export const propertyDetailsSpatial = pgTable(
@ -281,7 +291,7 @@ export const propertyDetailsSpatial = pgTable(
isListedBuilding: boolean("is_listed_building"),
isHeritageBuilding: boolean("is_heritage_building"),
},
(table) => [uniqueIndex("uq_property_details_spatial_uprn").on(table.uprn)]
(table) => [uniqueIndex("uq_property_details_spatial_uprn").on(table.uprn)],
);
export const propertyDetailsMeter = pgTable("property_details_meter", {