From e71f2aadfca2ea6b41c0abb586e1850ef93019d3 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 12 Jan 2026 09:49:44 -0800 Subject: [PATCH] fix: remove incorrect TEAM_BONUS records given to uplines TEAM_BONUS should only be given to the adopter themselves, not to their uplines. This migration deletes all TEAM_BONUS records where account_sequence != source_account_sequence. Also updates contribution_accounts totals in contribution-service. Co-Authored-By: Claude Opus 4.5 --- .../migration.sql | 35 +++++++++++++++++++ .../migration.sql | 7 ++++ 2 files changed, 42 insertions(+) create mode 100644 backend/services/contribution-service/prisma/migrations/20260113110000_fix_team_bonus_data/migration.sql create mode 100644 backend/services/mining-admin-service/prisma/migrations/20260113110000_fix_team_bonus_data/migration.sql diff --git a/backend/services/contribution-service/prisma/migrations/20260113110000_fix_team_bonus_data/migration.sql b/backend/services/contribution-service/prisma/migrations/20260113110000_fix_team_bonus_data/migration.sql new file mode 100644 index 00000000..bc4e6460 --- /dev/null +++ b/backend/services/contribution-service/prisma/migrations/20260113110000_fix_team_bonus_data/migration.sql @@ -0,0 +1,35 @@ +-- 清理错误的 TEAM_BONUS 记录 +-- TEAM_BONUS 只应该给认种人自己,即 account_sequence == source_account_sequence +-- 删除那些 account_sequence != source_account_sequence 的 TEAM_BONUS 记录 + +DELETE FROM contribution_records +WHERE source_type = 'TEAM_BONUS' + AND account_sequence != source_account_sequence; + +-- 同时需要更新 contribution_accounts 表中的 team_bonus_contribution 统计 +-- 重新计算每个账户的 team_bonus_contribution +UPDATE contribution_accounts ca +SET team_bonus_contribution = COALESCE( + (SELECT SUM(amount) + FROM contribution_records cr + WHERE cr.account_sequence = ca.account_sequence + AND cr.source_type = 'TEAM_BONUS' + AND cr.is_expired = false), + 0 +), +total_contribution = personal_contribution + team_level_contribution + COALESCE( + (SELECT SUM(amount) + FROM contribution_records cr + WHERE cr.account_sequence = ca.account_sequence + AND cr.source_type = 'TEAM_BONUS' + AND cr.is_expired = false), + 0 +), +effective_contribution = personal_contribution + team_level_contribution + COALESCE( + (SELECT SUM(amount) + FROM contribution_records cr + WHERE cr.account_sequence = ca.account_sequence + AND cr.source_type = 'TEAM_BONUS' + AND cr.is_expired = false), + 0 +); diff --git a/backend/services/mining-admin-service/prisma/migrations/20260113110000_fix_team_bonus_data/migration.sql b/backend/services/mining-admin-service/prisma/migrations/20260113110000_fix_team_bonus_data/migration.sql new file mode 100644 index 00000000..f1b26e04 --- /dev/null +++ b/backend/services/mining-admin-service/prisma/migrations/20260113110000_fix_team_bonus_data/migration.sql @@ -0,0 +1,7 @@ +-- 清理错误的 TEAM_BONUS 记录 +-- TEAM_BONUS 只应该给认种人自己,即 account_sequence == source_account_sequence +-- 删除那些 account_sequence != source_account_sequence 的 TEAM_BONUS 记录 + +DELETE FROM synced_contribution_records +WHERE source_type = 'TEAM_BONUS' + AND account_sequence != source_account_sequence;