mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
altering plan table
This commit is contained in:
parent
92cbcd8130
commit
f06e50a60f
6 changed files with 5567 additions and 27 deletions
34
src/app/db/migrations/0083_harsh_eternals.sql
Normal file
34
src/app/db/migrations/0083_harsh_eternals.sql
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
DO $$ BEGIN
|
||||
CREATE TYPE "housing_type" AS ENUM('Private', 'Social');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "scenario" (
|
||||
"id" bigserial PRIMARY KEY NOT NULL,
|
||||
"name" text,
|
||||
"budget" real,
|
||||
"portfolio_id" bigint NOT NULL,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL,
|
||||
"housing_type" "housing_type" NOT NULL,
|
||||
"goal" "goal" NOT NULL,
|
||||
"trigger_file_path" text,
|
||||
"already_installed_file_path" text,
|
||||
"patches_file_path" text,
|
||||
"non_invasive_recommendations_file_path" text,
|
||||
"exclusions" text,
|
||||
"multi_plan" boolean
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "plan" ADD COLUMN "scenario_id" bigint;--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "plan" ADD CONSTRAINT "plan_scenario_id_scenario_id_fk" FOREIGN KEY ("scenario_id") REFERENCES "scenario"("id") ON DELETE no action ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "scenario" ADD CONSTRAINT "scenario_portfolio_id_portfolio_id_fk" FOREIGN KEY ("portfolio_id") REFERENCES "portfolio"("id") ON DELETE no action ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
20
src/app/db/migrations/0084_brief_wolf_cub.sql
Normal file
20
src/app/db/migrations/0084_brief_wolf_cub.sql
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "cost";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "total_work_hours";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "energy_savings";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "co2_equivalent_savings";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "energy_cost_savings";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "epc_breakdown_pre_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "epc_breakdown_post_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "number_of_properties";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "n_units_to_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "co2_per_unit_pre_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "co2_per_unit_post_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "energy_bill_per_unit_pre_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "energy_bill_per_unit_post_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "energy_consumption_per_unit_pre_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "energy_consumption_per_unit_post_retrofit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "valuation_improvement_per_unit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "cost_per_unit";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "cost_per_co2_saved";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "cost_per_sap_point";--> statement-breakpoint
|
||||
ALTER TABLE "plan" DROP COLUMN IF EXISTS "valuation_return_on_investment";
|
||||
2782
src/app/db/migrations/meta/0083_snapshot.json
Normal file
2782
src/app/db/migrations/meta/0083_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
2662
src/app/db/migrations/meta/0084_snapshot.json
Normal file
2662
src/app/db/migrations/meta/0084_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -582,6 +582,20 @@
|
|||
"when": 1722356655029,
|
||||
"tag": "0082_strong_gateway",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 83,
|
||||
"version": "5",
|
||||
"when": 1722357312477,
|
||||
"tag": "0083_harsh_eternals",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 84,
|
||||
"version": "5",
|
||||
"when": 1722359514687,
|
||||
"tag": "0084_brief_wolf_cub",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { property } from "./property";
|
||||
import { portfolio } from "./portfolio";
|
||||
import { goalEnum, portfolio } from "./portfolio";
|
||||
import {
|
||||
bigserial,
|
||||
text,
|
||||
|
|
@ -13,6 +13,7 @@ import {
|
|||
} from "drizzle-orm/pg-core";
|
||||
import { Material, material } from "./materials";
|
||||
import { InferModel } from "drizzle-orm";
|
||||
import { ar } from "drizzle-orm/column.d-b7dc3bdb";
|
||||
|
||||
export const recommendation = pgTable("recommendation", {
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
|
|
@ -70,37 +71,40 @@ export const plan = pgTable("plan", {
|
|||
propertyId: bigint("property_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => property.id),
|
||||
scenarioId: bigint("scenario_id", { mode: "bigint" }).references(
|
||||
() => scenario.id
|
||||
),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
isDefault: boolean("is_default").notNull(),
|
||||
valuationIncreaseLowerBound: real("valuation_increase_lower_bound"),
|
||||
valuationIncreaseUpperBound: real("valuation_increase_upper_bound"),
|
||||
valuationIncreaseAverage: real("valuation_increase_average"),
|
||||
// Aggregations that were previously being stored against the portfolio, that are now being stored against the plan
|
||||
cost: real("cost"),
|
||||
totalWorkHours: real("total_work_hours"),
|
||||
energySavings: real("energy_savings"), // Unit is always kWh so we don't need to store unit
|
||||
co2EquivalentSavings: real("co2_equivalent_savings"), // Unit is always tonnes so we don't need to store unit
|
||||
energyCostSavings: real("energy_cost_savings"), // Unit is always £ so we don't need to store unit for the moment
|
||||
// Aggregates added for the summary tab
|
||||
epcBreakdownPreRetrofit: text("epc_breakdown_pre_retrofit"),
|
||||
epcBreakdownPostRetrofit: text("epc_breakdown_post_retrofit"),
|
||||
numberOfProperties: integer("number_of_properties"),
|
||||
nUnitsToRetrofit: integer("n_units_to_retrofit"),
|
||||
co2PerUnitPreRetrofit: text("co2_per_unit_pre_retrofit"),
|
||||
co2PerUnitPostRetrofit: text("co2_per_unit_post_retrofit"),
|
||||
energyBillPerUnitPreRetrofit: text("energy_bill_per_unit_pre_retrofit"),
|
||||
energyBillPerUnitPostRetrofit: text("energy_bill_per_unit_post_retrofit"),
|
||||
energyConsumptionPerUnitPreRetrofit: text(
|
||||
"energy_consumption_per_unit_pre_retrofit"
|
||||
),
|
||||
energyConsumptionPerUnitPostRetrofit: text(
|
||||
"energy_consumption_per_unit_post_retrofit"
|
||||
),
|
||||
valuationImprovementPerUnit: text("valuation_improvement_per_unit"),
|
||||
costPerUnit: text("cost_per_unit"),
|
||||
costPerCo2Saved: text("cost_per_co2_saved"),
|
||||
costPerSapPoint: text("cost_per_sap_point"),
|
||||
valuationReturnOnInvestment: text("valuation_return_on_investment"),
|
||||
// // Aggregations that were previously being stored against the portfolio, that are now being stored against the plan
|
||||
// cost: real("cost"),
|
||||
// totalWorkHours: real("total_work_hours"),
|
||||
// energySavings: real("energy_savings"), // Unit is always kWh so we don't need to store unit
|
||||
// co2EquivalentSavings: real("co2_equivalent_savings"), // Unit is always tonnes so we don't need to store unit
|
||||
// energyCostSavings: real("energy_cost_savings"), // Unit is always £ so we don't need to store unit for the moment
|
||||
// // Aggregates added for the summary tab
|
||||
// epcBreakdownPreRetrofit: text("epc_breakdown_pre_retrofit"),
|
||||
// epcBreakdownPostRetrofit: text("epc_breakdown_post_retrofit"),
|
||||
// numberOfProperties: integer("number_of_properties"),
|
||||
// nUnitsToRetrofit: integer("n_units_to_retrofit"),
|
||||
// co2PerUnitPreRetrofit: text("co2_per_unit_pre_retrofit"),
|
||||
// co2PerUnitPostRetrofit: text("co2_per_unit_post_retrofit"),
|
||||
// energyBillPerUnitPreRetrofit: text("energy_bill_per_unit_pre_retrofit"),
|
||||
// energyBillPerUnitPostRetrofit: text("energy_bill_per_unit_post_retrofit"),
|
||||
// energyConsumptionPerUnitPreRetrofit: text(
|
||||
// "energy_consumption_per_unit_pre_retrofit"
|
||||
// ),
|
||||
// energyConsumptionPerUnitPostRetrofit: text(
|
||||
// "energy_consumption_per_unit_post_retrofit"
|
||||
// ),
|
||||
// valuationImprovementPerUnit: text("valuation_improvement_per_unit"),
|
||||
// costPerUnit: text("cost_per_unit"),
|
||||
// costPerCo2Saved: text("cost_per_co2_saved"),
|
||||
// costPerSapPoint: text("cost_per_sap_point"),
|
||||
// valuationReturnOnInvestment: text("valuation_return_on_investment"),
|
||||
});
|
||||
|
||||
export const planRecommendations = pgTable("plan_recommendations", {
|
||||
|
|
@ -115,6 +119,30 @@ export const planRecommendations = pgTable("plan_recommendations", {
|
|||
.references(() => recommendation.id),
|
||||
});
|
||||
|
||||
export const HousingType: [string, ...string[]] = ["Private", "Social"];
|
||||
|
||||
export const housingTypeEnum = pgEnum("housing_type", HousingType);
|
||||
|
||||
export const scenario = pgTable("scenario", {
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
name: text("name"),
|
||||
budget: real("budget"),
|
||||
portfolioId: bigint("portfolio_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => portfolio.id),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
housingType: housingTypeEnum("housing_type").notNull(),
|
||||
goal: goalEnum("goal").notNull(),
|
||||
triggerFilePath: text("trigger_file_path"),
|
||||
alreadyInstalledFilePath: text("already_installed_file_path"),
|
||||
patchesFilePath: text("patches_file_path"),
|
||||
nonInvasideRecommendationsFilePath: text(
|
||||
"non_invasive_recommendations_file_path"
|
||||
),
|
||||
exclusions: text("exclusions"),
|
||||
multiPlan: boolean("multi_plan"),
|
||||
});
|
||||
|
||||
export type Plan = InferModel<typeof plan, "select">;
|
||||
export type Recommendation = InferModel<typeof recommendation, "select">;
|
||||
export type PlanRecommendations = InferModel<
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue