Files
junhong_cmp_fiber/migrations/000209_allow_commission_wallet_negative_balance.down.sql
break 586a1cccd5
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m25s
修复佣金回扣问题
2026-08-14 09:08:43 +08:00

14 lines
650 B
SQL
Raw Permalink 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.
-- 回滚恢复佣金commission钱包不允许负余额的旧约束。
-- 注意:若已存在负余额佣金数据,回滚会因违反检查约束而失败,属预期保护。
ALTER TABLE tb_agent_wallet
DROP CONSTRAINT chk_agent_wallet_available_balance;
ALTER TABLE tb_agent_wallet
ADD CONSTRAINT chk_agent_wallet_available_balance
CHECK (
(wallet_type = 'main' AND (balance::numeric - frozen_balance::numeric +
CASE WHEN credit_enabled THEN credit_limit::numeric ELSE 0::numeric END) >= 0::numeric)
OR
(wallet_type = 'commission' AND balance >= 0 AND frozen_balance <= balance)
);