From f7073943a5f094e255d337d666adf6a120205b1d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 10 Aug 2023 16:35:19 +0100 Subject: [PATCH] added additional fields to recommendations table and created plan and planRecommendations tables --- src/app/db/schema/recommendations.ts | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/app/db/schema/recommendations.ts b/src/app/db/schema/recommendations.ts index 264e00b..56ae813 100644 --- a/src/app/db/schema/recommendations.ts +++ b/src/app/db/schema/recommendations.ts @@ -1,3 +1,4 @@ +import { property } from "@/app/db/schema/property"; import { bigserial, text, @@ -27,6 +28,10 @@ export interface Recommendation { export const recommendation = pgTable("recommendation", { id: bigserial("id", { mode: "bigint" }).primaryKey(), + propertyId: bigint("property_id", { mode: "bigint" }) + .notNull() + .references(() => property.id), + createdAt: timestamp("created_at").notNull().defaultNow(), type: text("type").notNull(), description: text("description").notNull(), estimatedCost: real("estimated_cost"), @@ -35,7 +40,12 @@ export const recommendation = pgTable("recommendation", { newUValue: real("new_u_value"), sapPoints: real("sap_points"), heatDemand: real("heat_demand"), - createdAt: timestamp("created_at").notNull().defaultNow(), + co2EquivalentSavings: real("co2_equivalent_savings"), + energySavings: real("energy_savings"), + energyCostSavings: real("energy_cost_savings"), + propertyValuationIncrease: real("property_valuation_increase"), + rentalYieldIncrease: real("rental_yield_increase"), + totalWorkHours: real("total_work_hours"), }); export const recommendationMaterials = pgTable("recommendation_materials", { @@ -50,3 +60,21 @@ export const recommendationMaterials = pgTable("recommendation_materials", { .references(() => material.id), createdAt: timestamp("created_at").notNull().defaultNow(), }); + +export const plan = pgTable("plan", { + id: bigserial("id", { mode: "bigint" }).primaryKey(), + createdAt: timestamp("created_at").notNull().defaultNow(), + isDefault: boolean("is_default").notNull(), +}); + +export const planRecommendations = pgTable("plan_recommendations", { + id: bigserial("id", { mode: "bigint" }).primaryKey(), + planId: bigint("plan_id", { mode: "bigint" }) + .notNull() + .references(() => plan.id), + recommendationId: bigint("recommendation_id", { + mode: "bigint", + }) + .notNull() + .references(() => recommendation.id), +});