mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
added cascading delete
This commit is contained in:
parent
b29be8835f
commit
cb0475db58
8 changed files with 17022 additions and 18 deletions
6
src/app/db/migrations/0150_green_switch.sql
Normal file
6
src/app/db/migrations/0150_green_switch.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
ALTER TABLE "plan_recommendations" DROP CONSTRAINT "plan_recommendations_plan_id_plan_id_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "recommendation_materials" DROP CONSTRAINT "recommendation_materials_recommendation_id_recommendation_id_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "plan_recommendations" ADD CONSTRAINT "plan_recommendations_plan_id_plan_id_fk" FOREIGN KEY ("plan_id") REFERENCES "public"."plan"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "recommendation_materials" ADD CONSTRAINT "recommendation_materials_recommendation_id_recommendation_id_fk" FOREIGN KEY ("recommendation_id") REFERENCES "public"."recommendation"("id") ON DELETE cascade ON UPDATE no action;
|
||||
3
src/app/db/migrations/0151_regular_lila_cheney.sql
Normal file
3
src/app/db/migrations/0151_regular_lila_cheney.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE "plan_recommendations" DROP CONSTRAINT "plan_recommendations_recommendation_id_recommendation_id_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "plan_recommendations" ADD CONSTRAINT "plan_recommendations_recommendation_id_recommendation_id_fk" FOREIGN KEY ("recommendation_id") REFERENCES "public"."recommendation"("id") ON DELETE cascade ON UPDATE no action;
|
||||
3
src/app/db/migrations/0152_sparkling_kat_farrell.sql
Normal file
3
src/app/db/migrations/0152_sparkling_kat_farrell.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE "plan_recommendations" DROP CONSTRAINT "plan_recommendations_plan_id_plan_id_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "plan_recommendations" ADD CONSTRAINT "plan_recommendations_plan_id_plan_id_fk" FOREIGN KEY ("plan_id") REFERENCES "public"."plan"("id") ON DELETE no action ON UPDATE no action;
|
||||
5657
src/app/db/migrations/meta/0150_snapshot.json
Normal file
5657
src/app/db/migrations/meta/0150_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
5657
src/app/db/migrations/meta/0151_snapshot.json
Normal file
5657
src/app/db/migrations/meta/0151_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
5657
src/app/db/migrations/meta/0152_snapshot.json
Normal file
5657
src/app/db/migrations/meta/0152_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1051,6 +1051,27 @@
|
|||
"when": 1769597155526,
|
||||
"tag": "0149_rich_luminals",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 150,
|
||||
"version": "7",
|
||||
"when": 1771753702175,
|
||||
"tag": "0150_green_switch",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 151,
|
||||
"version": "7",
|
||||
"when": 1771754445853,
|
||||
"tag": "0151_regular_lila_cheney",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 152,
|
||||
"version": "7",
|
||||
"when": 1771754572720,
|
||||
"tag": "0152_sparkling_kat_farrell",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -95,15 +95,15 @@ export const recommendation = pgTable(
|
|||
index("idx_recommendation_active_defaults")
|
||||
.on(table.id)
|
||||
.where(
|
||||
sql`${table.default} = true AND ${table.alreadyInstalled} = false`
|
||||
sql`${table.default} = true AND ${table.alreadyInstalled} = false`,
|
||||
),
|
||||
|
||||
index("idx_recommendation_active_id_property")
|
||||
.on(table.id, table.propertyId)
|
||||
.where(
|
||||
sql`${table.default} = true AND ${table.alreadyInstalled} = false`
|
||||
sql`${table.default} = true AND ${table.alreadyInstalled} = false`,
|
||||
),
|
||||
]
|
||||
],
|
||||
);
|
||||
|
||||
export const unitQuantity: [string, ...string[]] = ["m2", "part", "kwp"];
|
||||
|
|
@ -117,7 +117,7 @@ export const recommendationMaterials = pgTable(
|
|||
mode: "bigint",
|
||||
})
|
||||
.notNull()
|
||||
.references(() => recommendation.id),
|
||||
.references(() => recommendation.id, { onDelete: "cascade" }),
|
||||
materialId: bigint("material_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => material.id),
|
||||
|
|
@ -129,9 +129,9 @@ export const recommendationMaterials = pgTable(
|
|||
},
|
||||
(table) => [
|
||||
index("recommendation_materials_recommendation_id_idx").on(
|
||||
table.recommendationId
|
||||
table.recommendationId,
|
||||
),
|
||||
]
|
||||
],
|
||||
);
|
||||
|
||||
// We create a plan type, for common plan types that we produce for clients
|
||||
|
|
@ -165,7 +165,7 @@ export const plan = pgTable(
|
|||
.references(() => property.id),
|
||||
|
||||
scenarioId: bigint("scenario_id", { mode: "bigint" }).references(
|
||||
() => scenario.id
|
||||
() => scenario.id,
|
||||
),
|
||||
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
|
|
@ -220,15 +220,15 @@ export const plan = pgTable(
|
|||
(table) => [
|
||||
index("idx_plan_portfolio_scenario").on(
|
||||
table.portfolioId,
|
||||
table.scenarioId
|
||||
table.scenarioId,
|
||||
),
|
||||
index("idx_plan_latest_per_property").on(
|
||||
table.portfolioId,
|
||||
table.scenarioId,
|
||||
table.propertyId,
|
||||
table.createdAt.desc()
|
||||
table.createdAt.desc(),
|
||||
),
|
||||
]
|
||||
],
|
||||
);
|
||||
|
||||
export const planRecommendations = pgTable(
|
||||
|
|
@ -242,15 +242,15 @@ export const planRecommendations = pgTable(
|
|||
mode: "bigint",
|
||||
})
|
||||
.notNull()
|
||||
.references(() => recommendation.id),
|
||||
.references(() => recommendation.id, { onDelete: "cascade" }),
|
||||
},
|
||||
(table) => [
|
||||
index("idx_plan_recommendations_plan_id").on(table.planId),
|
||||
index("idx_plan_recommendations_plan_rec").on(
|
||||
table.planId,
|
||||
table.recommendationId
|
||||
table.recommendationId,
|
||||
),
|
||||
]
|
||||
],
|
||||
);
|
||||
|
||||
export const HousingType: [string, ...string[]] = ["Private", "Social"];
|
||||
|
|
@ -273,7 +273,7 @@ export const scenario = pgTable("scenario", {
|
|||
alreadyInstalledFilePath: text("already_installed_file_path"),
|
||||
patchesFilePath: text("patches_file_path"),
|
||||
nonInvasideRecommendationsFilePath: text(
|
||||
"non_invasive_recommendations_file_path"
|
||||
"non_invasive_recommendations_file_path",
|
||||
),
|
||||
exclusions: text("exclusions"),
|
||||
multiPlan: boolean("multi_plan"),
|
||||
|
|
@ -298,10 +298,10 @@ export const scenario = pgTable("scenario", {
|
|||
energyBillPerUnitPreRetrofit: text("energy_bill_per_unit_pre_retrofit"),
|
||||
energyBillPerUnitPostRetrofit: text("energy_bill_per_unit_post_retrofit"),
|
||||
energyConsumptionPerUnitPreRetrofit: text(
|
||||
"energy_consumption_per_unit_pre_retrofit"
|
||||
"energy_consumption_per_unit_pre_retrofit",
|
||||
),
|
||||
energyConsumptionPerUnitPostRetrofit: text(
|
||||
"energy_consumption_per_unit_post_retrofit"
|
||||
"energy_consumption_per_unit_post_retrofit",
|
||||
),
|
||||
valuationImprovementPerUnit: text("valuation_improvement_per_unit"),
|
||||
costPerUnit: text("cost_per_unit"),
|
||||
|
|
@ -345,7 +345,7 @@ export const installedMeasure = pgTable(
|
|||
index("idx_installed_measure_uprn_measure")
|
||||
.on(table.uprn, table.measureType)
|
||||
.where(sql`${table.isActive} = true`),
|
||||
]
|
||||
],
|
||||
);
|
||||
|
||||
export type Plan = InferModel<typeof plan, "select">;
|
||||
|
|
@ -460,7 +460,7 @@ export const measuresDisplayLabels = {
|
|||
export type MeasureKey = keyof typeof measuresDisplayLabels;
|
||||
|
||||
export const measuresList: MeasureKey[] = Object.keys(
|
||||
measuresDisplayLabels
|
||||
measuresDisplayLabels,
|
||||
) as MeasureKey[];
|
||||
|
||||
export const MeasureKeyEnum = z.enum([
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue