migration for materials columns on recommendation table

This commit is contained in:
Daniel Roth 2026-06-05 10:03:34 +00:00
parent a2a5d7212a
commit 62b10ef808
4 changed files with 10795 additions and 3 deletions

View file

@ -0,0 +1,6 @@
ALTER TABLE "recommendation" ADD COLUMN "material_id" bigint;--> statement-breakpoint
ALTER TABLE "recommendation" ADD COLUMN "material_quantity" real;--> statement-breakpoint
ALTER TABLE "recommendation" ADD COLUMN "material_quantity_unit" "unit_quantity";--> statement-breakpoint
ALTER TABLE "recommendation" ADD COLUMN "material_depth" real;--> statement-breakpoint
ALTER TABLE "recommendation" ADD CONSTRAINT "recommendation_material_id_material_id_fk" FOREIGN KEY ("material_id") REFERENCES "public"."material"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_recommendation_material_id" ON "recommendation" USING btree ("material_id");

File diff suppressed because it is too large Load diff

View file

@ -1562,6 +1562,13 @@
"when": 1780647248894,
"tag": "0223_recommendation_plan_id_backfill",
"breakpoints": true
},
{
"idx": 224,
"version": "7",
"when": 1780653770494,
"tag": "0224_busy_nitro",
"breakpoints": true
}
]
}

View file

@ -60,6 +60,9 @@ export const measureTypeEnum = pgEnum("measure_type", [
"sealing_open_fireplace",
]);
export const unitQuantity: [string, ...string[]] = ["m2", "part", "kwp"];
export const unitQuantityEnum = pgEnum("unit_quantity", unitQuantity);
export const recommendation = pgTable(
"recommendation",
{
@ -70,6 +73,13 @@ export const recommendation = pgTable(
planId: bigint("plan_id", { mode: "bigint" }).references(() => plan.id, {
onDelete: "cascade",
}),
materialId: bigint("material_id", { mode: "bigint" }).references(
() => material.id,
{ onDelete: "set null" }
),
materialQuantity: real("material_quantity"),
materialQuantityUnit: unitQuantityEnum("material_quantity_unit"),
materialDepth: real("material_depth"),
createdAt: timestamp("created_at").notNull().defaultNow(),
type: text("type").notNull(),
measureType: text("measure_type"),
@ -107,12 +117,11 @@ export const recommendation = pgTable(
.where(
sql`${table.default} = true AND ${table.alreadyInstalled} = false`,
),
index("idx_recommendation_material_id").on(table.materialId),
],
);
export const unitQuantity: [string, ...string[]] = ["m2", "part", "kwp"];
export const unitQuantityEnum = pgEnum("unit_quantity", unitQuantity);
export const recommendationMaterials = pgTable(
"recommendation_materials",
{