summaryrefslogtreecommitdiff
path: root/makima/migrations/20260509000000_contract_lifecycle_states.sql
diff options
context:
space:
mode:
Diffstat (limited to 'makima/migrations/20260509000000_contract_lifecycle_states.sql')
-rw-r--r--makima/migrations/20260509000000_contract_lifecycle_states.sql19
1 files changed, 19 insertions, 0 deletions
diff --git a/makima/migrations/20260509000000_contract_lifecycle_states.sql b/makima/migrations/20260509000000_contract_lifecycle_states.sql
new file mode 100644
index 0000000..fc9c7bf
--- /dev/null
+++ b/makima/migrations/20260509000000_contract_lifecycle_states.sql
@@ -0,0 +1,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'));