Files
paliad/internal/db/migrations/091_drop_legacy_rule_columns.down.sql
mAi f9305d6108 feat(t-paliad-195): mig 091 — drop legacy rule columns
Phase 3 Slice 9 Step E (design §3.E, §9.1). m approved the
downtime window 2026-05-15 ("paliad ist nicht in use heute,
downtime ist egal") so the destructive drops can land.

Drops four superseded columns on paliad.deadline_rules:

  is_mandatory      → priority='mandatory' | other (Slice 2 mig 083)
  is_optional       → priority='optional'  (Slice 2 mig 083)
  condition_flag    → condition_expr  (Slice 2 mig 084)
  condition_rule_id → DEAD (no live rows, Q13 m's approved drop)

Pre-drop snapshot: paliad.deadline_rules_pre_091 (id +
the four columns + snapshotted_at). Lets the down-migration
restore values to existing rows; a follow-up cleanup slice drops
the snapshot table once the rule editor's migration-export flow
has been used to roll any post-drop edits back into version
control.

Hard assertions at end:
  - count(priority IS NULL) == 0 (Slice 2 mig 083 must have run).
  - count(rule with pre-drop condition_flag but no condition_expr)
    == 0 (Slice 2 mig 084 must have populated every row).
Both raise EXCEPTION on violation — fails the migration loudly
before legacy code paths get pulled out from under the unified
calculator.

Audit-reason wrapper set; ALTER TABLE DROP COLUMN doesn't fire
the mig 079 row-level trigger, but the wrapper is the standard
Phase 3 pattern.

Sibling drops deferred — see live-data audit in head ping:
  - mig 092 (event_deadlines + trigger_events tables): SKIPPED.
    trigger_events has 33 event_types FKs + 77 deadline_rules
    FKs; event_deadlines + event_deadline_rule_codes still
    consumed by EventDeadlineService.Calculate for the frontend's
    "Was kommt nach…" tab (/api/tools/event-deadlines is still
    in use post-Slice-3 delegate).
  - mig 093 (retire litigation category): SKIPPED. 40 active
    deadline_rules still reference litigation-category
    proceeding_types (the Pipeline-A INF/REV/CCR/APM/APP/AMD/
    ZPO_CIVIL rules; Slice 5 retired them from project-binding,
    not from the rule corpus).

Both deferrals are tracked in the head ping; the litigation drop
can land after a focused slice that splits the Pipeline-A rules
off the litigation category onto a fristenrechner-side parent.
The event_deadlines drop needs EventDeadlineService.Calculate
to stop reading the source rows first.
2026-05-15 17:53:08 +02:00

33 lines
1.3 KiB
SQL

-- t-paliad-195 down — reverses 091_drop_legacy_rule_columns.up.sql.
--
-- Restores the four columns and re-populates them from the
-- paliad.deadline_rules_pre_091 snapshot. Rules created AFTER the
-- mig 091 cutover (via the rule editor's POST /admin/api/rules)
-- won't have a snapshot entry — they get NULL on the restored
-- columns, which matches their original "never had these legacy
-- fields" state.
--
-- The snapshot table itself stays (it's a permanent audit artefact);
-- a focused follow-up slice / Slice 12 cleanup drops it once the
-- rule editor's migration-export flow has been used to roll any
-- post-drop edits back into version control.
SELECT set_config(
'paliad.audit_reason',
'rollback 091: restore legacy columns from pre-drop snapshot',
true);
ALTER TABLE paliad.deadline_rules
ADD COLUMN IF NOT EXISTS is_mandatory boolean NOT NULL DEFAULT true,
ADD COLUMN IF NOT EXISTS is_optional boolean NOT NULL DEFAULT false,
ADD COLUMN IF NOT EXISTS condition_flag text[],
ADD COLUMN IF NOT EXISTS condition_rule_id uuid;
UPDATE paliad.deadline_rules dr
SET is_mandatory = b.is_mandatory,
is_optional = b.is_optional,
condition_flag = b.condition_flag,
condition_rule_id = b.condition_rule_id
FROM paliad.deadline_rules_pre_091 b
WHERE dr.id = b.id;