Files
LWLT-AI/control-plane/migrations/004_erp_execution_idempotency.sql
2026-07-13 19:57:46 +08:00

11 lines
450 B
SQL

-- A business task may be dispatched to ERP at most once. Any uncertain outcome
-- is reconciled against ERP instead of creating a second execution attempt.
CREATE UNIQUE INDEX IF NOT EXISTS task_attempts_single_erp_execution_idx
ON task_attempts (task_id)
WHERE phase = 'erp';
CREATE INDEX IF NOT EXISTS tasks_erp_lease_idx
ON tasks (lease_expires_at)
WHERE status IN ('queued', 'accepted', 'running')
AND lease_owner LIKE 'browser:%';