mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
completed materials, recommendations and recommendationsMaterials migration
This commit is contained in:
parent
5bef451fd0
commit
f3637ee2b9
4 changed files with 1164 additions and 1 deletions
|
|
@ -3,6 +3,8 @@ import { drizzle } from "drizzle-orm/node-postgres";
|
|||
import { Pool } from "pg";
|
||||
import * as portfolioSchema from "@/app/db/schema/portfolio";
|
||||
import * as propertySchema from "@/app/db/schema/property";
|
||||
import * as recommendationSchema from "@/app/db/schema/recommendations";
|
||||
import * as materialSchema from "@/app/db/schema/materials";
|
||||
|
||||
export const pool = new Pool({
|
||||
host: process.env.DB_HOST,
|
||||
|
|
@ -15,6 +17,8 @@ export const pool = new Pool({
|
|||
const schema = {
|
||||
...portfolioSchema,
|
||||
...propertySchema,
|
||||
...recommendationSchema,
|
||||
...materialSchema,
|
||||
};
|
||||
|
||||
export const db = drizzle(pool, {
|
||||
|
|
|
|||
76
src/app/db/migrations/0024_clean_polaris.sql
Normal file
76
src/app/db/migrations/0024_clean_polaris.sql
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
DO $$ BEGIN
|
||||
CREATE TYPE "cost_unit" AS ENUM('gbp_sq_meter');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "depth_unit" AS ENUM('mm');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "type" AS ENUM('suspended_floor_insulation', 'solid_floor_insulation', 'external_wall_insulation', 'internal_wall_insulation');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "r_value_unit" AS ENUM('square_meter_kelvin_per_watt');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "thermal_conductivity_unit" AS ENUM('watt_per_meter_kelvin');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "material" (
|
||||
"id" bigserial PRIMARY KEY NOT NULL,
|
||||
"type" "type" NOT NULL,
|
||||
"description" text NOT NULL,
|
||||
"json" json,
|
||||
"depth_unit" "depth_unit",
|
||||
"cost" real,
|
||||
"cost_unit" "cost_unit",
|
||||
"r_value_per_mm" real,
|
||||
"r_value_unit" "r_value_unit",
|
||||
"thermal_conductivity" real,
|
||||
"thermal_conductivity_unit" "thermal_conductivity_unit",
|
||||
"link" text,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "recommendation" (
|
||||
"id" bigserial PRIMARY KEY NOT NULL,
|
||||
"type" text NOT NULL,
|
||||
"description" text NOT NULL,
|
||||
"estimated_cost" real,
|
||||
"default" boolean NOT NULL,
|
||||
"new_u_value" real,
|
||||
"sap_points" real,
|
||||
"heat_demand" real,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "recommendation_materials" (
|
||||
"id" bigserial PRIMARY KEY NOT NULL,
|
||||
"recommendation_id" bigint NOT NULL,
|
||||
"material_id" bigint NOT NULL,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "recommendation_materials" ADD CONSTRAINT "recommendation_materials_recommendation_id_recommendation_id_fk" FOREIGN KEY ("recommendation_id") REFERENCES "recommendation"("id") ON DELETE no action ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "recommendation_materials" ADD CONSTRAINT "recommendation_materials_material_id_material_id_fk" FOREIGN KEY ("material_id") REFERENCES "material"("id") ON DELETE no action ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
1076
src/app/db/migrations/meta/0024_snapshot.json
Normal file
1076
src/app/db/migrations/meta/0024_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -169,6 +169,13 @@
|
|||
"when": 1690970372309,
|
||||
"tag": "0023_mute_avengers",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 24,
|
||||
"version": "5",
|
||||
"when": 1691664707792,
|
||||
"tag": "0024_clean_polaris",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue