new tables for magicplan ventilation. move opening type from window table to window ventilation table

This commit is contained in:
Daniel Roth 2026-06-08 09:25:16 +00:00
parent 899ac432ea
commit b16e0f7d3d
11 changed files with 32804 additions and 7 deletions

View file

@ -0,0 +1,21 @@
CREATE TABLE "magic_plan_door_ventilation" (
"id" bigserial PRIMARY KEY NOT NULL,
"magic_plan_door_id" bigint NOT NULL,
"undercut_mm" real,
CONSTRAINT "magic_plan_door_ventilation_magic_plan_door_id_unique" UNIQUE("magic_plan_door_id")
);
--> statement-breakpoint
CREATE TABLE "magic_plan_window_ventilation" (
"id" bigserial PRIMARY KEY NOT NULL,
"magic_plan_window_id" bigint NOT NULL,
"opening_type" text,
"num_openings" integer,
"pct_openable" integer,
"trickle_vent_area_mm2" integer,
"num_trickle_vents" integer,
CONSTRAINT "magic_plan_window_ventilation_magic_plan_window_id_unique" UNIQUE("magic_plan_window_id")
);
--> statement-breakpoint
ALTER TABLE "magic_plan_door" ADD COLUMN "height_mm" real;--> statement-breakpoint
ALTER TABLE "magic_plan_door_ventilation" ADD CONSTRAINT "magic_plan_door_ventilation_magic_plan_door_id_magic_plan_door_id_fk" FOREIGN KEY ("magic_plan_door_id") REFERENCES "public"."magic_plan_door"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "magic_plan_window_ventilation" ADD CONSTRAINT "magic_plan_window_ventilation_magic_plan_window_id_magic_plan_window_id_fk" FOREIGN KEY ("magic_plan_window_id") REFERENCES "public"."magic_plan_window"("id") ON DELETE cascade ON UPDATE no action;

View file

@ -0,0 +1,10 @@
-- Backfill opening_type into magic_plan_window_ventilation from magic_plan_window.
-- Only rows with a non-null opening_type are backfilled; no ventilation row is
-- created for windows that never had one. The unique constraint on
-- magic_plan_window_id prevents duplicate rows if this runs more than once.
INSERT INTO magic_plan_window_ventilation (magic_plan_window_id, opening_type)
SELECT id, opening_type
FROM magic_plan_window
WHERE opening_type IS NOT NULL
ON CONFLICT (magic_plan_window_id) DO NOTHING;

View file

@ -0,0 +1 @@
ALTER TABLE "magic_plan_window" DROP COLUMN "opening_type";

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1576,6 +1576,27 @@
"when": 1780654800000,
"tag": "0225_recommendation_material_id_backfill",
"breakpoints": true
},
{
"idx": 226,
"version": "7",
"when": 1780910378978,
"tag": "0226_massive_guardian",
"breakpoints": true
},
{
"idx": 227,
"version": "7",
"when": 1780910400000,
"tag": "0227_magic_plan_window_ventilation_backfill",
"breakpoints": true
},
{
"idx": 228,
"version": "7",
"when": 1780910657380,
"tag": "0228_deep_betty_ross",
"breakpoints": true
}
]
}

View file

@ -9,6 +9,7 @@ export const magicPlanDoor = pgTable(
.notNull()
.references(() => magicPlanRoom.id),
widthMm: real("width_mm"),
heightMm: real("height_mm"),
type: text("type"),
},
);

View file

@ -0,0 +1,14 @@
import { pgTable, bigserial, bigint, real } from "drizzle-orm/pg-core";
import { magicPlanDoor } from "./door";
export const magicPlanDoorVentilation = pgTable(
"magic_plan_door_ventilation",
{
id: bigserial("id", { mode: "bigint" }).primaryKey(),
doorId: bigint("magic_plan_door_id", { mode: "bigint" })
.notNull()
.unique()
.references(() => magicPlanDoor.id, { onDelete: "cascade" }),
undercutMm: real("undercut_mm"),
},
);

View file

@ -1,16 +1,15 @@
import { pgTable, bigserial, bigint, text, real } from "drizzle-orm/pg-core";
import { pgTable, bigserial, bigint, real } from "drizzle-orm/pg-core";
import { magicPlanRoom } from "./room";
export const magicPlanWindow = pgTable(
"magic_plan_window",
{
id: bigserial("id", { mode: "bigint" }).primaryKey(),
roomId: bigint("magic_plan_room_id", { mode: "bigint" })
id: bigserial("id", { mode: "bigint" }).primaryKey(),
roomId: bigint("magic_plan_room_id", { mode: "bigint" })
.notNull()
.references(() => magicPlanRoom.id),
widthM: real("width_m"),
heightM: real("height_m"),
areaM2: real("area_m2"),
openingType: text("opening_type"),
widthM: real("width_m"),
heightM: real("height_m"),
areaM2: real("area_m2"),
},
);

View file

@ -0,0 +1,18 @@
import { pgTable, bigserial, bigint, text, integer } from "drizzle-orm/pg-core";
import { magicPlanWindow } from "./window";
export const magicPlanWindowVentilation = pgTable(
"magic_plan_window_ventilation",
{
id: bigserial("id", { mode: "bigint" }).primaryKey(),
windowId: bigint("magic_plan_window_id", { mode: "bigint" })
.notNull()
.unique()
.references(() => magicPlanWindow.id, { onDelete: "cascade" }),
openingType: text("opening_type"),
numOpenings: integer("num_openings"),
pctOpenable: integer("pct_openable"),
trickleVentAreaMm2: integer("trickle_vent_area_mm2"),
numTrickleVents: integer("num_trickle_vents"),
},
);