Adds the schema scaffolding for the fourth approval action (alongside
Approve / Reject / Revoke):
1. Extends approval_requests.status CHECK to include 'changes_requested'.
2. Adds counter_payload jsonb — the approver's edited values on a
changes_requested row (the basis of the new row's payload).
3. Adds previous_request_id uuid FK — back-pointer from a SuggestChanges-
spawned row to its source. Partial index on the FK supports chain
traversal.
Non-blocking: extending a CHECK constraint is metadata-only on Postgres;
adding NULLable columns + a NULLable FK is metadata-only. Safe for live
deploy.
Dry-run validated against the live youpc paliad schema via BEGIN/ROLLBACK
(migration tracker at 102 pre-apply; schema unchanged post-rollback).
28 lines
1.1 KiB
SQL
28 lines
1.1 KiB
SQL
-- Reverse of 103_approval_suggest_changes.up.sql.
|
|
--
|
|
-- Drops the previous_request_id index + column, drops counter_payload, and
|
|
-- restores the original status CHECK (without 'changes_requested'). If any
|
|
-- live rows are at status='changes_requested' OR carry a non-NULL
|
|
-- counter_payload OR previous_request_id, the down will fail on the CHECK
|
|
-- restore. That is intentional: it forces an explicit cleanup decision
|
|
-- before tearing the schema back.
|
|
|
|
SELECT set_config(
|
|
'paliad.audit_reason',
|
|
'mig 103 DOWN: revert suggest-changes schema extensions (t-paliad-216)',
|
|
true);
|
|
|
|
DROP INDEX IF EXISTS paliad.approval_requests_previous_idx;
|
|
|
|
ALTER TABLE paliad.approval_requests
|
|
DROP COLUMN IF EXISTS previous_request_id;
|
|
|
|
ALTER TABLE paliad.approval_requests
|
|
DROP COLUMN IF EXISTS counter_payload;
|
|
|
|
ALTER TABLE paliad.approval_requests
|
|
DROP CONSTRAINT IF EXISTS approval_requests_status_check;
|
|
ALTER TABLE paliad.approval_requests
|
|
ADD CONSTRAINT approval_requests_status_check
|
|
CHECK (status IN ('pending', 'approved', 'rejected', 'revoked', 'superseded'));
|