-- 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:%';
