summaryrefslogtreecommitdiff
path: root/makima/migrations/20260509000000_contract_lifecycle_states.sql
blob: fc9c7bf976ecef4e3c1bf203e3622f43fb995b64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- Add 'queued' to the contract status enum.
--
-- The unified directive workflow runs contracts sequentially in the
-- directive's shared worktree — only one contract is `active` at a time.
-- When a user clicks "Lock & Start" on a draft, it goes to `active` if
-- the slot is free, otherwise it goes to `queued` and waits for the
-- current active contract to ship/archive. The `complete_contract`
-- handler auto-promotes the lowest-position `queued` row to `active`.
--
-- The constraint replacement is straightforward — drop + re-add. No
-- existing rows can be in 'queued' yet, so the new CHECK is satisfied
-- by every row.

ALTER TABLE directive_documents
    DROP CONSTRAINT IF EXISTS directive_documents_status_check;

ALTER TABLE directive_documents
    ADD CONSTRAINT directive_documents_status_check
    CHECK (status IN ('draft', 'queued', 'active', 'shipped', 'archived'));