更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -1,18 +1,3 @@
|
||||
// 全量迁移:把业务表中的老 uid(yz_system_tenant_user.uid)统一替换为
|
||||
// 认证中心的 identity_id(yz_auth_identity.id)。
|
||||
//
|
||||
// 背景:统一认证上线后,令牌里的 user_id 是 identity_id;而业务表的
|
||||
// uid / user_id / create_user_id / owner_user_id / uploader_id 等字段存的仍是
|
||||
// 老表 uid。不迁移的话用户会「找不到自己的数据」,因此做全量替换而非兼容层。
|
||||
//
|
||||
// 用法(需在 go/ 目录运行,读取 conf/app.conf):
|
||||
//
|
||||
// go run scripts/uidmigrate/migrate_uid.go -check 预检:列出受影响的表/列/行数
|
||||
// go run scripts/uidmigrate/migrate_uid.go -apply 执行迁移(记录变更日志,可回滚)
|
||||
// go run scripts/uidmigrate/migrate_uid.go -rollback 按变更日志回滚
|
||||
//
|
||||
// 说明:本脚本直接使用 database/sql,避免 beego ORM 的 Raw 取值差异。
|
||||
// 执行前请先自行备份数据库(mysqldump)。
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -28,16 +13,13 @@ import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
// tempOffset 中间值偏移:先把旧值搬到远离目标值的区间,避免新旧值重叠导致错改
|
||||
const tempOffset = 1000000000
|
||||
|
||||
// 需要处理的列名
|
||||
var uidColumns = []string{
|
||||
"uid", "user_id", "create_user_id", "update_user_id",
|
||||
"owner_user_id", "uploader_id", "operator_id", "tuid",
|
||||
}
|
||||
|
||||
// 不参与迁移的表
|
||||
var skipTables = map[string]bool{
|
||||
"yz_system_tenant_user": true,
|
||||
"yz_users": true,
|
||||
@@ -94,10 +76,6 @@ func openDB() (*sql.DB, error) {
|
||||
return sql.Open("mysql", dsn)
|
||||
}
|
||||
|
||||
// buildMapping 建立「老 uid → identity_id」映射:同企业(tid) 下账号/手机/邮箱 一致。
|
||||
//
|
||||
// 注意:老表是 utf8mb4_0900_ai_ci、新表是 utf8mb4_unicode_ci,直接 JOIN 比较字符串
|
||||
// 会触发 Illegal mix of collations,因此改为在 Go 侧匹配。
|
||||
func buildMapping() (map[uint64]uint64, error) {
|
||||
legacy := make([]struct {
|
||||
uid uint64
|
||||
@@ -155,7 +133,6 @@ func buildMapping() (map[uint64]uint64, error) {
|
||||
return mapping, nil
|
||||
}
|
||||
|
||||
// mergeKey 归并键:企业ID + (手机号 > 邮箱 > 账号)
|
||||
func mergeKey(tid uint64, account, phone, email string) string {
|
||||
base := fmt.Sprintf("%d:", tid)
|
||||
if v := strings.TrimSpace(phone); v != "" {
|
||||
@@ -258,7 +235,6 @@ func runApply() {
|
||||
if oldUID == newUID {
|
||||
continue
|
||||
}
|
||||
// 阶段一:旧值 → 临时值;阶段二:临时值 → 新值
|
||||
cnt := execUpdate(c.Table, c.Col, oldUID, oldUID+tempOffset)
|
||||
if cnt == 0 {
|
||||
continue
|
||||
@@ -298,7 +274,6 @@ func runRollback() {
|
||||
return
|
||||
}
|
||||
for _, it := range list {
|
||||
// 反向:新值 → 临时值 → 旧值
|
||||
execUpdate(it.table, it.col, it.newV, it.newV+tempOffset)
|
||||
cnt := execUpdate(it.table, it.col, it.newV+tempOffset, it.oldV)
|
||||
log.Printf(" 回滚 %s.%s: %d → %d(%d 行)", it.table, it.col, it.newV, it.oldV, cnt)
|
||||
@@ -306,8 +281,6 @@ func runRollback() {
|
||||
log.Println("回滚完成")
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 工具
|
||||
|
||||
func execUpdate(table, col string, from, to uint64) int64 {
|
||||
res, err := db.Exec(fmt.Sprintf(
|
||||
"UPDATE `%s` SET `%s` = ? WHERE `%s` = ?", table, col, col), to, from)
|
||||
|
||||
Reference in new issue
Block a user