added additional fields to recommendations table and created plan and planRecommendations tables

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-10 16:35:19 +01:00
parent f3637ee2b9
commit f7073943a5

View file

@ -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),
});