backfill_user_steam_account_limit.sql 838 B

123456789101112131415161718
  1. /*
  2. ============================================================
  3. 为已存在的用户回填 user_steam_account_limit 配置
  4. 执行前请确保已创建表 user_steam_account_limit。
  5. 仅为尚未在 user_steam_account_limit 中有记录的用户插入一条默认配置(max_steam_accounts = 3)。
  6. ============================================================
  7. */
  8. SET NAMES utf8mb4;
  9. -- 为所有未配置的用户插入默认 Steam 账号上限(3)
  10. -- 仅插入 users 中 is_deleted = 0 且不在 user_steam_account_limit 中的 user_id
  11. INSERT INTO `user_steam_account_limit` (`user_id`, `max_steam_accounts`, `created_at`, `updated_at`)
  12. SELECT u.`id`, 3, NOW(), NOW()
  13. FROM `users` u
  14. LEFT JOIN `user_steam_account_limit` l ON l.`user_id` = u.`id`
  15. WHERE (u.`is_deleted` = 0 OR u.`is_deleted` IS NULL)
  16. AND l.`user_id` IS NULL;