Files
hi-server/initialize/migrate/database/02150_refund_pending_withdrawals.down.sql
T
shanshanzhong147 0169a16ada
Build docker and publish / build (20.15.1) (push) Failing after 8m17s
fix: make refund migration compatible with legacy schemas
Co-authored-by: multica-agent <github@multica.ai>
2026-05-25 11:07:06 -07:00

20 lines
744 B
SQL

-- Rollback: re-deduct commission for users with pending (status=0) withdrawals.
-- This re-applies the OLD behaviour where commission is deducted on application.
-- Only run this if you are rolling back to the old code; do NOT run against
-- the new code or commission will be double-deducted on approval.
UPDATE `user` u
JOIN (
SELECT user_id, COALESCE(SUM(amount), 0) AS pending_total
FROM withdrawals
WHERE status = 0
GROUP BY user_id
) p ON u.id = p.user_id
SET u.commission = u.commission - p.pending_total
WHERE p.pending_total > 0;
-- Remove the migration log entries written by the up migration.
DELETE FROM system_logs
WHERE type = 33
AND content LIKE '%migration: refund pending withdrawal commission (HIF-22)%';