Files
qnc-server-v3/deploy/sql/user_temp_migration.sql
2025-12-13 17:44:18 +08:00

45 lines
1.1 KiB
SQL
Raw Permalink 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.

-- 将 user_temp 迁移为 usermobile 为空)与 user_auth
START TRANSACTION;
-- 1) 迁移临时用户到 usermobile 置为空)
INSERT INTO
`user` (
`delete_time`,
`del_state`,
`version`,
`mobile`,
`password`,
`nickname`,
`info`,
`inside`
)
SELECT NULL, 0, COALESCE(ut.version, 0), NULL, NULL, NULL, '', 0
FROM `user_temp` ut
WHERE
ut.del_state = 0;
-- 2) 将临时认证迁移到 user_auth按插入顺序关联最近插入的 user.id
INSERT INTO
`user_auth` (
`delete_time`,
`del_state`,
`version`,
`user_id`,
`auth_key`,
`auth_type`
)
SELECT NULL, 0, COALESCE(ut.version, 0), u.id, ut.auth_key, ut.auth_type
FROM `user_temp` ut
JOIN `user` u ON u.del_state = 0
AND u.mobile IS NULL
WHERE
ut.del_state = 0;
-- 注意以上为示意实际生产应通过显式映射如临时ID与新UserID映射表确保一一对应避免笛卡尔匹配。
COMMIT;
-- 唯一索引保障
ALTER TABLE `user_auth`
ADD UNIQUE INDEX `idx_auth_type_key` (`auth_type`, `auth_key`);