mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
backfill materials columns for recommendation table
This commit is contained in:
parent
62b10ef808
commit
694bac47e1
3 changed files with 10803 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
-- Guard: fail if any recommendation maps to more than one material row.
|
||||
-- The modelled fabric measures never produce this; if real data violates it
|
||||
-- the backfill cannot pick deterministically and must not proceed silently.
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM recommendation_materials
|
||||
GROUP BY recommendation_id
|
||||
HAVING count(*) > 1
|
||||
) THEN
|
||||
RAISE EXCEPTION
|
||||
'recommendation_material_id backfill aborted: one or more recommendations '
|
||||
'have multiple recommendation_materials rows. Resolve cardinality before re-running.';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Backfill all four columns in a single pass.
|
||||
UPDATE recommendation r
|
||||
SET material_id = rm.material_id,
|
||||
material_quantity = rm.quantity,
|
||||
material_quantity_unit = rm.quantity_unit,
|
||||
material_depth = rm.depth
|
||||
FROM recommendation_materials rm
|
||||
WHERE rm.recommendation_id = r.id
|
||||
AND r.material_id IS NULL;
|
||||
10770
src/app/db/migrations/meta/0225_snapshot.json
Normal file
10770
src/app/db/migrations/meta/0225_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1569,6 +1569,13 @@
|
|||
"when": 1780653770494,
|
||||
"tag": "0224_busy_nitro",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 225,
|
||||
"version": "7",
|
||||
"when": 1780654800000,
|
||||
"tag": "0225_recommendation_material_id_backfill",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue