Files
Document_translator_1panel/migrations/merge_duplicate_users.sql
beabigegg 6599716481 1panel
2025-10-03 08:19:40 +08:00

19 lines
788 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.

-- 合併重複的使用者記錄
-- 保留 ID=3 的記錄 (較新且有較多關聯資料)
-- 將 ID=1 的關聯資料轉移到 ID=3然後刪除 ID=1
-- 1. 將 ID=1 的 system_logs 轉移到 ID=3
UPDATE dt_system_logs SET user_id = 3 WHERE user_id = 1;
-- 2. 確認沒有其他關聯資料需要轉移
-- (dt_translation_jobs, dt_api_usage_stats 都已經在 ID=3)
-- 3. 刪除重複的記錄 ID=1
DELETE FROM dt_users WHERE id = 1;
-- 4. 驗證結果
SELECT 'After merge:' as status;
SELECT id, username, display_name, email FROM dt_users WHERE email = 'ymirliu@panjit.com.tw';
SELECT 'Jobs:', COUNT(*) FROM dt_translation_jobs WHERE user_id = 3;
SELECT 'Logs:', COUNT(*) FROM dt_system_logs WHERE user_id = 3;
SELECT 'Stats:', COUNT(*) FROM dt_api_usage_stats WHERE user_id = 3;