ALTER TABLE work_orders
  ADD COLUMN deadline_at TIMESTAMPTZ,
  ADD COLUMN timeout_minutes INTEGER NOT NULL DEFAULT 0,
  ADD COLUMN timeout_policy TEXT NOT NULL DEFAULT 'reopen';

CREATE INDEX idx_work_orders_deadline
  ON work_orders(status, deadline_at)
  WHERE deadline_at IS NOT NULL;

ALTER TABLE work_product_rules
  ADD COLUMN timeout_minutes INTEGER NOT NULL DEFAULT 0,
  ADD COLUMN timeout_policy TEXT NOT NULL DEFAULT 'reopen';

COMMENT ON COLUMN work_orders.deadline_at IS '代练超时截止时间，打手抢单后按时限计算';
COMMENT ON COLUMN work_orders.timeout_minutes IS '任务时限（分钟），0 表示不限时';
COMMENT ON COLUMN work_orders.timeout_policy IS '超时处置策略：reopen 退押金回大厅 / cancel_release 取消退押金 / cancel_deduct 取消扣押金';
COMMENT ON COLUMN work_product_rules.timeout_minutes IS '规则默认任务时限（分钟），0 表示不限时';
COMMENT ON COLUMN work_product_rules.timeout_policy IS '规则默认超时处置策略';
