Phase 3 Slice 2 Step B-3. Convert condition_flag text[] →
condition_expr jsonb per DESIGN §2.4 long form (NOT msg 1746's
short {"and":[...]} form — head clarified in msg 1750 that
design §2.4 wins because long form parses uniformly across
and/or/not, matching what the Slice-4 calculator + Slice-11 rule
editor will emit).
Mapping:
['with_ccr'] → {"flag":"with_ccr"} (5 rows)
['with_amend'] → {"flag":"with_amend"} (4 rows)
['with_cci'] → {"flag":"with_cci"} (4 rows)
['with_ccr', 'with_amend'] → {"op":"and","args":[
{"flag":"with_ccr"},
{"flag":"with_amend"}
]} (4 rows)
NULL or {} → NULL (155 rows)
Total translated: 17 rows.
Single-flag is unwrapped (no AND wrapper) per design §2.4 — a
shortcut equivalent to a 1-arg AND that saves a layer of nesting
without losing semantics. The calculator's parser treats
{"flag":"<name>"} as the leaf and {"op":"<and|or|not>","args":[…]}
as the canonical boolean node.
jsonb construction uses jsonb_build_object + a LATERAL unnest…WITH
ORDINALITY over the flag array so args[] order matches the source
array exactly (load-bearing if a future migration adds order-
sensitive ops).
Idempotent via WHERE condition_expr IS NULL — re-running doesn't
double-write audit rows for already-translated rules. Migration
ends with a DO block that RAISE EXCEPTION if any non-empty
condition_flag row still has NULL condition_expr (catches a
broken translation path before it reaches Slice 4).
15 lines
543 B
SQL
15 lines
543 B
SQL
-- t-paliad-183 down — reverts the condition_expr translations written
|
|
-- by 084_backfill_condition_expr.up.sql. Mig 078 created the column
|
|
-- with NULL on every row; resetting non-NULL values to NULL undoes the
|
|
-- backfill cleanly (condition_flag is the source of truth for the
|
|
-- legacy code path and stays untouched).
|
|
|
|
SELECT set_config(
|
|
'paliad.audit_reason',
|
|
'rollback 084: reset condition_expr to mig 078 default (NULL)',
|
|
true);
|
|
|
|
UPDATE paliad.deadline_rules
|
|
SET condition_expr = NULL
|
|
WHERE condition_expr IS NOT NULL;
|