Redefine drizzle tables to match new data structure defined by backend

This commit is contained in:
Daniel Roth 2026-01-27 17:23:34 +00:00
parent c35b53d186
commit 30ea9a6488
5 changed files with 255 additions and 244 deletions

View file

@ -0,0 +1,20 @@
import { bigint, bigserial, date, integer, pgTable, text } from "drizzle-orm/pg-core";
import { element } from "./element";
import { aspectType } from "./aspect_type";
export const aspectCondition = pgTable("aspect_condition", {
id: bigserial("id", { mode: "bigint" }).primaryKey(),
elementId: bigint("element_id", { mode: "number" })
.notNull()
.references(() => element.id),
aspectType: aspectType("aspect_type").notNull(),
aspectInstance: integer("aspect_instance").notNull(),
value: text("value"),
quantity: integer("quantity"),
installDate: date("install_date"),
renewalYear: integer("renewal_year"),
comments: text("comments"),
});

View file

@ -1,40 +0,0 @@
import {
bigserial,
text,
date,
pgTable,
integer,
bigint,
uniqueIndex,
} from "drizzle-orm/pg-core";
import { element } from "./element";
import { aspectType } from "./aspect_type";
import { InferSelectModel } from "drizzle-orm";
export const assetCondition = pgTable(
"asset_condition",
{
id: bigserial("id", { mode: "bigint" }).primaryKey(),
uprn: bigint("uprn", { mode: "number" }).notNull(),
element: element("element").notNull(),
aspectType: aspectType("aspect_type").notNull(),
elementInstance: integer("element_instance"),
value: text("value"),
quantity: integer("quantity"),
installDate: date("install_date"),
renewalYear: integer("renewal_year"),
sourceSystem: text("source_system"),
comments: text("comments"),
},
(t) => [uniqueIndex("asset_condition_uprn_element_aspect_instance")
.on(t.uprn, t.element, t.aspectType, t.elementInstance),
]
);
export type AssetConditionRow = InferSelectModel<typeof assetCondition>;

View file

@ -1,206 +1,14 @@
import { pgEnum } from "drizzle-orm/pg-core";
import { bigint, bigserial, integer, pgTable } from "drizzle-orm/pg-core";
import { propertyConditionSurvey } from "./property_condition_survey";
import { elementType } from "./element_type";
export const element = pgEnum("element", [
"property",
"property_construction_type",
"property_classification",
"property_age_band",
"storey_count",
"floor_level",
"floor_level_front_door",
"accessible_housing_register",
"asbestos",
"quality_standard",
"ccu",
"passenger_lift",
"stairlift",
"disabled_hoist_tracking",
"disabled_facilities",
"steps_to_front_door",
"roof",
"pitched_roof_covering",
"flat_roof_covering",
"rainwater_goods",
"loft_insulation",
"porch_canopy",
"chimney",
"fascia",
"soffit",
"fascia_soffit_bargeboards",
"gutters",
"store_roof",
"garage_roof",
"garage_and_store_roof",
"external_wall",
"external_noise_insulation",
"primary_wall",
"secondary_wall",
"downpipes",
"external_decoration",
"cladding",
"spandrel_panels",
"garage_walls",
"party_wall_fire_break",
"external_brickwork_pointing",
"internal_downpipes_external_area",
"external_windows",
"communal_windows",
"secondary_glazing",
"store_windows",
"garage_windows",
"garage_and_store_windows",
"external_door",
"front_door",
"rear_door",
"store_door",
"garage_door",
"garage_and_store_door",
"communal_entrance_door",
"main_door",
"block_entrance_door",
"lintel",
"patio_french_door",
"door_entry_handset",
"paths_and_hardstandings",
"parking_areas",
"boundary_walls",
"front_fencing",
"rear_fencing",
"side_fencing",
"rear_gate",
"front_gate",
"gates",
"retaining_walls",
"private_balcony",
"balcony_balustrade",
"outbuildings",
"garage_structure",
"paving",
"roads",
"soil_and_vent",
"solar_thermals",
"drop_kerb",
"outbuilding_overhaul",
"external_structural_defects",
"access_ramp",
"kitchen",
"kitchen_space_layout",
"tenant_installed_kitchen",
"kitchen_extractor_fan",
"bathroom",
"secondary_bathroom",
"secondary_toilet",
"bathroom_extractor_fan",
"additional_wc_or_whb",
"bathroom_remaining_life_source",
"kitchen_remaining_life_source",
"central_heating",
"heating_boiler",
"heating_distribution",
"secondary_heating",
"hot_water_system",
"cold_water_storage",
"heating_system",
"boiler_fuel",
"water_heating",
"programmable_heating",
"community_heating",
"gas_available",
"heat_recovery_units",
"heating_improvements",
"electrical_wiring",
"consumer_unit",
"smoke_detection",
"heat_detection",
"carbon_monoxide_detection",
"fire_door_rating",
"fire_risk_assessment",
"internal_wiring",
"electrics",
"communal_heating",
"communal_boiler",
"communal_electrics",
"communal_fire_alarm",
"communal_emergency_lighting",
"communal_door_entry",
"communal_cctv",
"communal_bin_store",
"communal_bin_store_doors",
"communal_bin_store_walls",
"communal_bin_store_roof",
"communal_refuse_chute",
"communal_floor_covering",
"communal_kitchen",
"communal_bathroom",
"communal_toilets",
"communal_gates",
"communal_lift",
"communal_passenger_lift",
"communal_balcony_walkway",
"communal_entrance",
"communal_internal_decorations",
"communal_internal_floor",
"communal_walkways",
"communal_external_doors",
"communal_stairs",
"communal_aerial",
"communal_aov",
"communal_internal_doors",
"communal_lateral_mains",
"communal_lighting",
"communal_lighting_conductor",
"communal_store_roof",
"communal_store_walls",
"communal_store_doors",
"communal_warden_call_system",
"communal_bms",
"communal_booster_pump",
"communal_dry_riser",
"communal_wet_riser",
"communal_cold_water_storage",
"communal_sprinkler",
"communal_plug_sockets",
"communal_circulation_space",
"ffhh_damp",
"ffhh_hold_and_cold_water",
"ffhh_drainage_lavatories",
"ffhh_neglected",
"ffhh_natural_light",
"ffhh_ventilation",
"ffhh_food_prep_and_washup",
"ffhh_unsafe_layout",
"ffhh_unstable_building",
"hhsrs_damp_and_mould",
"hhsrs_excess_cold",
"hhsrs_excess_heat",
"hhsrs_asbestos_and_mmf",
"hhsrs_biocides",
"hhsrs_carbon_monoxide",
"hhsrs_lead",
"hhsrs_radiation",
"hhsrs_uncombusted_fuel_gas",
"hhsrs_volatile_organic_compounds",
"hhsrs_crowding_and_space",
"hhsrs_entry_by_intruders",
"hhsrs_lighting",
"hhsrs_noise",
"hhsrs_domestic_hygiene_pests_refuse",
"hhsrs_food_safety",
"hhsrs_personal_hygiene_sanitation",
"hhsrs_water_supply",
"hhsrs_falls_associated_with_baths",
"hhsrs_falls_on_level_surfaces",
"hhsrs_falls_on_stairs",
"hhsrs_falls_between_levels",
"hhsrs_electrical_hazards",
"hhsrs_fire",
"hhsrs_flames_hot_surfaces",
"hhsrs_collision_and_entrapment",
"hhsrs_collision_hazards_low_headroom",
"hhsrs_explosions",
"hhsrs_ergonomics",
"hhsrs_structural_collapse",
"hhsrs_amenities",
]);
export const element = pgTable("element", {
id: bigserial("id", { mode: "bigint" }).primaryKey(),
export type Element = typeof element.enumValues[number];
surveyId: bigint("survey_id", { mode: "number" })
.notNull()
.references(() => propertyConditionSurvey.id),
elementType: elementType("element_type").notNull(),
elementInstance: integer("element_instance").notNull(),
});

View file

@ -0,0 +1,206 @@
import { pgEnum } from "drizzle-orm/pg-core";
export const elementType = pgEnum("element_type", [
"property",
"property_construction_type",
"property_classification",
"property_age_band",
"storey_count",
"floor_level",
"floor_level_front_door",
"accessible_housing_register",
"asbestos",
"quality_standard",
"ccu",
"passenger_lift",
"stairlift",
"disabled_hoist_tracking",
"disabled_facilities",
"steps_to_front_door",
"roof",
"pitched_roof_covering",
"flat_roof_covering",
"rainwater_goods",
"loft_insulation",
"porch_canopy",
"chimney",
"fascia",
"soffit",
"fascia_soffit_bargeboards",
"gutters",
"store_roof",
"garage_roof",
"garage_and_store_roof",
"external_wall",
"external_noise_insulation",
"primary_wall",
"secondary_wall",
"downpipes",
"external_decoration",
"cladding",
"spandrel_panels",
"garage_walls",
"party_wall_fire_break",
"external_brickwork_pointing",
"internal_downpipes_external_area",
"external_windows",
"communal_windows",
"secondary_glazing",
"store_windows",
"garage_windows",
"garage_and_store_windows",
"external_door",
"front_door",
"rear_door",
"store_door",
"garage_door",
"garage_and_store_door",
"communal_entrance_door",
"main_door",
"block_entrance_door",
"lintel",
"patio_french_door",
"door_entry_handset",
"paths_and_hardstandings",
"parking_areas",
"boundary_walls",
"front_fencing",
"rear_fencing",
"side_fencing",
"rear_gate",
"front_gate",
"gates",
"retaining_walls",
"private_balcony",
"balcony_balustrade",
"outbuildings",
"garage_structure",
"paving",
"roads",
"soil_and_vent",
"solar_thermals",
"drop_kerb",
"outbuilding_overhaul",
"external_structural_defects",
"access_ramp",
"kitchen",
"kitchen_space_layout",
"tenant_installed_kitchen",
"kitchen_extractor_fan",
"bathroom",
"secondary_bathroom",
"secondary_toilet",
"bathroom_extractor_fan",
"additional_wc_or_whb",
"bathroom_remaining_life_source",
"kitchen_remaining_life_source",
"central_heating",
"heating_boiler",
"heating_distribution",
"secondary_heating",
"hot_water_system",
"cold_water_storage",
"heating_system",
"boiler_fuel",
"water_heating",
"programmable_heating",
"community_heating",
"gas_available",
"heat_recovery_units",
"heating_improvements",
"electrical_wiring",
"consumer_unit",
"smoke_detection",
"heat_detection",
"carbon_monoxide_detection",
"fire_door_rating",
"fire_risk_assessment",
"internal_wiring",
"electrics",
"communal_heating",
"communal_boiler",
"communal_electrics",
"communal_fire_alarm",
"communal_emergency_lighting",
"communal_door_entry",
"communal_cctv",
"communal_bin_store",
"communal_bin_store_doors",
"communal_bin_store_walls",
"communal_bin_store_roof",
"communal_refuse_chute",
"communal_floor_covering",
"communal_kitchen",
"communal_bathroom",
"communal_toilets",
"communal_gates",
"communal_lift",
"communal_passenger_lift",
"communal_balcony_walkway",
"communal_entrance",
"communal_internal_decorations",
"communal_internal_floor",
"communal_walkways",
"communal_external_doors",
"communal_stairs",
"communal_aerial",
"communal_aov",
"communal_internal_doors",
"communal_lateral_mains",
"communal_lighting",
"communal_lighting_conductor",
"communal_store_roof",
"communal_store_walls",
"communal_store_doors",
"communal_warden_call_system",
"communal_bms",
"communal_booster_pump",
"communal_dry_riser",
"communal_wet_riser",
"communal_cold_water_storage",
"communal_sprinkler",
"communal_plug_sockets",
"communal_circulation_space",
"ffhh_damp",
"ffhh_hold_and_cold_water",
"ffhh_drainage_lavatories",
"ffhh_neglected",
"ffhh_natural_light",
"ffhh_ventilation",
"ffhh_food_prep_and_washup",
"ffhh_unsafe_layout",
"ffhh_unstable_building",
"hhsrs_damp_and_mould",
"hhsrs_excess_cold",
"hhsrs_excess_heat",
"hhsrs_asbestos_and_mmf",
"hhsrs_biocides",
"hhsrs_carbon_monoxide",
"hhsrs_lead",
"hhsrs_radiation",
"hhsrs_uncombusted_fuel_gas",
"hhsrs_volatile_organic_compounds",
"hhsrs_crowding_and_space",
"hhsrs_entry_by_intruders",
"hhsrs_lighting",
"hhsrs_noise",
"hhsrs_domestic_hygiene_pests_refuse",
"hhsrs_food_safety",
"hhsrs_personal_hygiene_sanitation",
"hhsrs_water_supply",
"hhsrs_falls_associated_with_baths",
"hhsrs_falls_on_level_surfaces",
"hhsrs_falls_on_stairs",
"hhsrs_falls_between_levels",
"hhsrs_electrical_hazards",
"hhsrs_fire",
"hhsrs_flames_hot_surfaces",
"hhsrs_collision_and_entrapment",
"hhsrs_collision_hazards_low_headroom",
"hhsrs_explosions",
"hhsrs_ergonomics",
"hhsrs_structural_collapse",
"hhsrs_amenities",
]);
export type Element = typeof elementType.enumValues[number];

View file

@ -0,0 +1,17 @@
import {
pgTable,
bigserial,
bigint,
date,
text,
integer,
} from "drizzle-orm/pg-core";
export const propertyConditionSurvey = pgTable("property_condition_survey", {
id: bigserial("id", { mode: "bigint" }).primaryKey(),
uprn: bigint("uprn", { mode: "number" }).notNull(),
date: date("date").notNull(),
source: text("source").notNull(),
});