diff --git a/internal/db/migrations/098_submission_codes_prefix_and_rename.up.sql b/internal/db/migrations/098_submission_codes_prefix_and_rename.up.sql index 6980afe..4df6f16 100644 --- a/internal/db/migrations/098_submission_codes_prefix_and_rename.up.sql +++ b/internal/db/migrations/098_submission_codes_prefix_and_rename.up.sql @@ -240,13 +240,17 @@ BEGIN v_bad_shape; END IF; - -- 6.2 No NULL submission_code on active+published rows. The column - -- is nullable for legacy reasons, but every live row should - -- carry a code after the prefix step. + -- 6.2 No NULL submission_code on active+published rows that BELONG + -- to a proceeding. Orphan rows (`proceeding_type_id IS NULL`) + -- are cross-cutting rules without a fixed proceeding home + -- (Wiedereinsetzung, Schriftsatznachreichung, etc.) — they + -- legitimately carry NULL submission_code because there's no + -- proceeding to prefix with. Exempt them. SELECT count(*) INTO v_null_codes FROM paliad.deadline_rules WHERE is_active = true AND lifecycle_state = 'published' + AND proceeding_type_id IS NOT NULL AND submission_code IS NULL; IF v_null_codes <> 0 THEN RAISE EXCEPTION