-- Reverses 039_condition_flag_to_array. Casts text[] back to text by
-- taking the first element when present (single-element arrays
-- round-trip exactly; multi-element arrays would lose info, but no such
-- rules exist before Phase B1 lands which itself ships after this
-- migration). Down-stepping past Phase B1 in production would require
-- B1's down to remove its multi-flag rules first.

ALTER TABLE paliad.deadline_rules
    ALTER COLUMN condition_flag TYPE text
    USING (CASE WHEN condition_flag IS NULL OR cardinality(condition_flag) = 0 THEN NULL
                ELSE condition_flag[1]
           END);
