Skip to content

Commit

Permalink
add: 分表保留数字最大的
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-home committed May 17, 2023
1 parent a44fccf commit bf0c2cd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions console/commands/orm/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,21 +473,26 @@ func Filter(tableColumns map[string][]tableColumn) TableInfo {
Columns: make(map[string][]tableColumn),
Infos: make(map[string]TableInfos),
}

tableSort := make(map[string]int)
for tableName, columns := range tableColumns {
arr := strings.Split(tableName, "_")
arrLen := len(arr)
if arrLen > 1 {
str := arr[arrLen-1]
_, err := strconv.Atoi(str)
tn, err := strconv.Atoi(str)
if err == nil {
tableName = strings.ReplaceAll(tableName, "_"+str, "")
info.Infos[tableName] = TableInfos{
"sub": "true", // 分表
}
// 保留数字最大的
n, ok := tableSort[tableName]
if ok && n > tn {
continue
}
tableSort[tableName] = tn
}
}

info.Columns[tableName] = columns
}
return info
Expand Down

0 comments on commit bf0c2cd

Please sign in to comment.