-- 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'));
