Files
ycc-proxy-server/deploy/sql/user_system_refactor.sql
2025-12-05 18:30:31 +08:00

44 lines
1.8 KiB
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.

-- ============================================
-- 用户系统重构SQL脚本简化版 - 开发环境)
-- 根据《用户系统重构计划书》执行
-- ============================================
-- ============================================
-- 第一部分UserAuth表唯一索引
-- ============================================
-- 确保user_auth表的(auth_type, auth_key)唯一性
-- 如果已存在同名索引,先删除
ALTER TABLE `user_auth` DROP INDEX IF EXISTS `uk_auth_type_key`;
-- 添加唯一索引
ALTER TABLE `user_auth`
ADD UNIQUE INDEX `uk_auth_type_key` (`auth_type`, `auth_key`) COMMENT '确保同一个认证方式只能绑定一个用户';
-- ============================================
-- 第二部分删除UserTemp表开发环境直接删除
-- ============================================
-- 注意:开发环境没有数据,直接删除表即可
-- 如果表不存在,会报错但可以忽略
DROP TABLE IF EXISTS `user_temp`;
-- ============================================
-- 第三部分:索引优化(可选)
-- ============================================
-- 为user_auth表添加user_id和auth_type的联合索引如果查询频繁
-- ALTER TABLE `user_auth`
-- ADD INDEX `idx_user_id_auth_type` (`user_id`, `auth_type`) COMMENT '优化按用户查询认证类型';
-- 为user表添加mobile的唯一索引如果不存在
-- ALTER TABLE `user`
-- ADD UNIQUE INDEX `uk_mobile` (`mobile`) COMMENT '确保手机号唯一性';
-- ============================================
-- 注意事项
-- ============================================
-- 1. 此脚本适用于开发环境直接删除UserTemp表
-- 2. 如果生产环境有数据,请使用完整版迁移脚本
-- 3. 执行后确保代码中已移除所有对UserTemp表的引用