Files
junhong_cmp_fiber/migrations/000069_add_order_expiration.up.sql
huang e661b59bb9
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m58s
feat: 实现订单超时自动取消功能,支持钱包余额解冻和 Asynq Scheduler 统一调度
- 新增 expires_at 字段和复合索引,待支付订单 30 分钟超时自动取消
- 实现 cancelOrder/unfreezeWalletForCancel 钱包余额解冻逻辑
- 创建 Asynq 定时任务(order_expire/alert_check/data_cleanup)
- 将原有 time.Ticker 轮询迁移至 Asynq Scheduler 统一调度
- 同步 delta specs 到 main specs 并归档变更
2026-02-28 17:16:15 +08:00

25 lines
883 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 添加订单过期时间字段和复合索引
DO $$
BEGIN
-- 添加 expires_at 字段订单过期时间NULL 表示不过期)
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name='tb_order'
AND column_name='expires_at'
) THEN
ALTER TABLE tb_order ADD COLUMN expires_at TIMESTAMPTZ;
COMMENT ON COLUMN tb_order.expires_at IS '订单过期时间NULL表示不过期待支付订单默认30分钟后过期';
END IF;
-- 创建复合索引:用于定时任务扫描超时待支付订单
IF NOT EXISTS (
SELECT 1 FROM pg_indexes
WHERE tablename='tb_order'
AND indexname='idx_order_expires'
) THEN
CREATE INDEX idx_order_expires ON tb_order (expires_at, payment_status)
WHERE expires_at IS NOT NULL AND deleted_at IS NULL;
END IF;
END
$$;