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

master
Kevin Wan 3 years ago committed by GitHub
parent 0cc9d4ff8d
commit 415c4c91fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,7 @@
package gen
import (
"sort"
"strings"
"github.com/zeromicro/go-zero/core/collection"
@ -19,6 +20,10 @@ func genDelete(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)
camel := table.Name.ToCamel()
text, err := pathx.LoadTemplate(category, deleteTemplateFile, template.Delete)
@ -34,9 +39,9 @@ func genDelete(table Table, withCache, postgreSql bool) (string, string, error)
"containsIndexCache": table.ContainsUniqueCacheKey,
"lowerStartCamelPrimaryKey": util.EscapeGolangKeyword(stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle()),
"dataType": table.PrimaryKey.DataType,
"keys": strings.Join(keySet.KeysStr(), "\n"),
"keys": strings.Join(keys, "\n"),
"originalPrimaryKey": wrapWithRawString(table.PrimaryKey.Name.Source(), postgreSql),
"keyValues": strings.Join(keyVariableSet.KeysStr(), ", "),
"keyValues": strings.Join(keyVars, ", "),
"postgreSql": postgreSql,
"data": table,
})

@ -82,7 +82,8 @@ func genFindOneByField(table Table, withCache, postgreSql bool) (*findOneCode, e
}
if withCache {
text, err := pathx.LoadTemplate(category, findOneByFieldExtraMethodTemplateFile, template.FindOneByFieldExtraMethod)
text, err := pathx.LoadTemplate(category, findOneByFieldExtraMethodTemplateFile,
template.FindOneByFieldExtraMethod)
if err != nil {
return nil, err
}

@ -2,6 +2,7 @@ package gen
import (
"fmt"
"sort"
"strings"
"github.com/zeromicro/go-zero/core/collection"
@ -20,6 +21,10 @@ func genInsert(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)
expressions := make([]string, 0)
expressionValues := make([]string, 0)
@ -59,8 +64,8 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error)
"lowerStartCamelObject": stringx.From(camel).Untitle(),
"expression": strings.Join(expressions, ", "),
"expressionValues": strings.Join(expressionValues, ", "),
"keys": strings.Join(keySet.KeysStr(), "\n"),
"keyValues": strings.Join(keyVariableSet.KeysStr(), ", "),
"keys": strings.Join(keys, "\n"),
"keyValues": strings.Join(keyVars, ", "),
"data": table,
})
if err != nil {

@ -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(),

Loading…
Cancel
Save