Adding new fields to plans table

This commit is contained in:
Khalim Conn-Kowlessar 2024-07-30 17:26:14 +01:00
parent 258c22fb3a
commit 92cbcd8130
8 changed files with 5257 additions and 2 deletions

View file

@ -42,5 +42,9 @@ export async function GET(
},
});
if (!propertyMeta) {
return new NextResponse(null, { status: 404 });
}
return new NextResponse(JSON.stringify(propertyMeta, serializeBigInt));
}

View file

@ -0,0 +1 @@
ALTER TABLE "plan" ADD COLUMN "name" text;

View file

@ -0,0 +1,20 @@
ALTER TABLE "plan" ADD COLUMN "cost" real;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "total_work_hours" real;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "energy_savings" real;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "co2_equivalent_savings" real;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "energy_cost_savings" real;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "epc_breakdown_pre_retrofit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "epc_breakdown_post_retrofit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "number_of_properties" integer;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "n_units_to_retrofit" integer;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "co2_per_unit_pre_retrofit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "co2_per_unit_post_retrofit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "energy_bill_per_unit_pre_retrofit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "energy_bill_per_unit_post_retrofit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "energy_consumption_per_unit_pre_retrofit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "energy_consumption_per_unit_post_retrofit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "valuation_improvement_per_unit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "cost_per_unit" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "cost_per_co2_saved" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "cost_per_sap_point" text;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "valuation_return_on_investment" text;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -568,6 +568,20 @@
"when": 1722269231130,
"tag": "0080_glossy_avengers",
"breakpoints": true
},
{
"idx": 81,
"version": "5",
"when": 1722355117022,
"tag": "0081_nebulous_ezekiel",
"breakpoints": true
},
{
"idx": 82,
"version": "5",
"when": 1722356655029,
"tag": "0082_strong_gateway",
"breakpoints": true
}
]
}

View file

@ -9,6 +9,7 @@ import {
boolean,
bigint,
pgEnum,
integer,
} from "drizzle-orm/pg-core";
import { Material, material } from "./materials";
import { InferModel } from "drizzle-orm";
@ -62,6 +63,7 @@ export const recommendationMaterials = pgTable("recommendation_materials", {
export const plan = pgTable("plan", {
id: bigserial("id", { mode: "bigint" }).primaryKey(),
name: text("name"),
portfolioId: bigint("portfolio_id", { mode: "bigint" })
.notNull()
.references(() => portfolio.id),
@ -73,6 +75,32 @@ export const plan = pgTable("plan", {
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"),
});
export const planRecommendations = pgTable("plan_recommendations", {

View file

@ -1,8 +1,8 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"target": "es5",
// "target": "ESNext",
// "target": "es5",
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,