mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
add guard clause when backfilling plan_id to recommendation
This commit is contained in:
parent
694bac47e1
commit
d2c9c0696a
1 changed files with 18 additions and 0 deletions
|
|
@ -1,3 +1,21 @@
|
|||
-- Guard: fail if any recommendation is linked to more than one plan.
|
||||
-- The spec asserts each recommendation belongs to exactly one plan; if real
|
||||
-- data violates that the backfill cannot pick deterministically and must not
|
||||
-- proceed silently.
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM plan_recommendations
|
||||
GROUP BY recommendation_id
|
||||
HAVING count(*) > 1
|
||||
) THEN
|
||||
RAISE EXCEPTION
|
||||
'plan_id backfill aborted: one or more recommendations appear in multiple '
|
||||
'plan_recommendations rows. Resolve cardinality before re-running.';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
UPDATE recommendation r
|
||||
SET plan_id = pr.plan_id
|
||||
FROM plan_recommendations pr
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue