fix: model unique keys generated differently in each re-generation (#1771)

This commit is contained in:
Kevin Wan
2022-04-09 00:25:23 +08:00
committed by GitHub
parent 0cc9d4ff8d
commit 415c4c91fc
4 changed files with 23 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package gen
import (
"sort"
"strings"
"github.com/zeromicro/go-zero/core/collection"
@@ -33,6 +34,10 @@ func genUpdate(table Table, withCache, postgreSql bool) (string, string, error)
keySet.AddStr(key.DataKeyExpression)
keyVariableSet.AddStr(key.KeyLeft)
}
keys := keySet.KeysStr()
sort.Strings(keys)
keyVars := keyVariableSet.KeysStr()
sort.Strings(keyVars)
if postgreSql {
expressionValues = append([]string{"data." + table.PrimaryKey.Name.ToCamel()}, expressionValues...)
@@ -50,8 +55,8 @@ func genUpdate(table Table, withCache, postgreSql bool) (string, string, error)
Execute(map[string]interface{}{
"withCache": withCache,
"upperStartCamelObject": camelTableName,
"keys": strings.Join(keySet.KeysStr(), "\n"),
"keyValues": strings.Join(keyVariableSet.KeysStr(), ", "),
"keys": strings.Join(keys, "\n"),
"keyValues": strings.Join(keyVars, ", "),
"primaryCacheKey": table.PrimaryCacheKey.DataKeyExpression,
"primaryKeyVariable": table.PrimaryCacheKey.KeyLeft,
"lowerStartCamelObject": stringx.From(camelTableName).Untitle(),