-- +goose Up

-- 修正历史外部上传中以 VX/WX 表示微信扫码、但被默认归类为 QQ 的账号。
UPDATE game_accounts AS a
JOIN rental_listings AS l ON l.account_id = a.id
SET a.server_region = '微信'
WHERE a.server_region = 'QQ'
  AND EXISTS (
    SELECT 1
    FROM listing_uploads AS lu
    WHERE lu.listing_id = l.id
  )
  AND (
    a.login_platform LIKE '%微信%'
    OR LOWER(TRIM(a.login_platform)) LIKE 'vx%'
    OR LOWER(TRIM(a.login_platform)) LIKE 'wx%'
  );

-- +goose Down

-- 此数据修复不可逆，避免将已修正的微信账号错误回退为 QQ。
