steam_account_migrations_execute.sql 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. ============================================================
  3. Steam 账号相关:表结构修改 + 新表
  4. 在目标库执行前请确认当前库中 steam_accounts 结构,按需执行对应部分。
  5. ============================================================
  6. 一、表结构修改(已有旧版 steam_accounts / steam_accounts_his 时执行)
  7. 二、新表:每用户 Steam 账号数量上限
  8. ============================================================
  9. */
  10. SET NAMES utf8mb4;
  11. SET FOREIGN_KEY_CHECKS = 0;
  12. -- ============================================================
  13. -- 一、steam_accounts 表结构修改(精简:删除敏感字段)
  14. -- 仅当表中存在 shared_secret、identity_secret 时执行,否则会报错
  15. -- ============================================================
  16. ALTER TABLE `steam_accounts`
  17. DROP COLUMN `shared_secret`,
  18. DROP COLUMN `identity_secret`;
  19. -- 若表中还有 last_used_time 列,可取消下面注释执行:
  20. -- ALTER TABLE `steam_accounts` DROP COLUMN `last_used_time`;
  21. -- ============================================================
  22. -- 一、steam_accounts_his 表结构修改(与主表一致精简)
  23. -- 仅当该表存在且含有 shared_secret、identity_secret 时执行
  24. -- ============================================================
  25. -- ALTER TABLE `steam_accounts_his`
  26. -- DROP COLUMN `shared_secret`,
  27. -- DROP COLUMN `identity_secret`;
  28. -- 若还有 last_used_time:
  29. -- ALTER TABLE `steam_accounts_his` DROP COLUMN `last_used_time`;
  30. -- ============================================================
  31. -- 二、新表:每用户 Steam 账号绑定数量上限
  32. -- 每个用户一条记录,默认 3;管理员可为不同用户设不同上限
  33. -- ============================================================
  34. DROP TABLE IF EXISTS `user_steam_account_limit`;
  35. CREATE TABLE `user_steam_account_limit` (
  36. `user_id` int(11) NOT NULL COMMENT '用户ID',
  37. `max_steam_accounts` int(11) NOT NULL DEFAULT 3 COMMENT '该用户最多可绑定的 Steam 账号数',
  38. `created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  39. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  40. PRIMARY KEY (`user_id`),
  41. KEY `idx_max_steam_accounts` (`max_steam_accounts`)
  42. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='每用户Steam账号绑定数量上限';
  43. SET FOREIGN_KEY_CHECKS = 1;
  44. /*
  45. ============================================================
  46. 【可选】若需从零建表或按新结构重建 steam_accounts / steam_accounts_his
  47. 请单独执行下面整段(会 DROP 再 CREATE,数据会清空)
  48. ============================================================
  49. SET NAMES utf8mb4;
  50. SET FOREIGN_KEY_CHECKS = 0;
  51. DROP TABLE IF EXISTS `steam_accounts_his`;
  52. DROP TABLE IF EXISTS `steam_accounts`;
  53. CREATE TABLE `steam_accounts` (
  54. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  55. `user_id` int(11) NOT NULL COMMENT '用户ID',
  56. `steam_username` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Steam用户名',
  57. `steam_id` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Steam ID(来自登录验证)',
  58. `is_active` tinyint(1) DEFAULT '1' COMMENT '是否启用:1-启用,0-禁用',
  59. `is_deleted` tinyint(1) DEFAULT '0' COMMENT '是否删除:0-否,1-是',
  60. `created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '绑定时间',
  61. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  62. PRIMARY KEY (`id`),
  63. KEY `idx_user_id` (`user_id`),
  64. KEY `idx_steam_username` (`steam_username`),
  65. KEY `idx_is_deleted` (`is_deleted`)
  66. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Steam账号绑定表(仅账号信息,敏感数据存本地)';
  67. CREATE TABLE `steam_accounts_his` (
  68. `id` int(11) NOT NULL COMMENT '原表主键ID',
  69. `user_id` int(11) NOT NULL COMMENT '用户ID',
  70. `steam_username` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Steam用户名',
  71. `steam_id` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Steam ID',
  72. `is_active` tinyint(1) DEFAULT '1' COMMENT '是否启用',
  73. `is_deleted` tinyint(1) DEFAULT '0' COMMENT '是否删除',
  74. `created_at` datetime DEFAULT NULL COMMENT '绑定时间',
  75. `updated_at` datetime DEFAULT NULL COMMENT '更新时间',
  76. `his_created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '历史记录创建时间',
  77. `his_operation` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '操作类型:INSERT/UPDATE/DELETE',
  78. PRIMARY KEY (`id`,`his_created_at`),
  79. KEY `idx_user_id` (`user_id`)
  80. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Steam账号绑定表历史';
  81. DROP TABLE IF EXISTS `user_steam_account_limit`;
  82. CREATE TABLE `user_steam_account_limit` (
  83. `user_id` int(11) NOT NULL COMMENT '用户ID',
  84. `max_steam_accounts` int(11) NOT NULL DEFAULT 3 COMMENT '该用户最多可绑定的 Steam 账号数',
  85. `created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  86. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  87. PRIMARY KEY (`user_id`),
  88. KEY `idx_max_steam_accounts` (`max_steam_accounts`)
  89. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='每用户Steam账号绑定数量上限';
  90. SET FOREIGN_KEY_CHECKS = 1;
  91. */