fix index name is type, parseFieldIndexes will set index TYPE is "TYPE"

This commit is contained in:
labulakalia 2022-03-14 11:48:45 +08:00 committed by labulaka
parent f961bf1c14
commit 9695ddf4f1
2 changed files with 11 additions and 5 deletions

View File

@ -92,7 +92,8 @@ func parseFieldIndexes(field *Field) (indexes []Index) {
name string
tag = strings.Join(v[1:], ":")
idx = strings.Index(tag, ",")
settings = ParseTagSetting(tag, ",")
tagSetting = strings.Join(strings.Split(tag, ",")[1:], ",")
settings = ParseTagSetting(tagSetting, ",")
length, _ = strconv.Atoi(settings["LENGTH"])
)

View File

@ -18,6 +18,7 @@ type UserIndex struct {
Age int64 `gorm:"index:profile,expression:ABS(age),option:WITH PARSER parser_name"`
OID int64 `gorm:"index:idx_id;index:idx_oid,unique"`
MemberNumber string `gorm:"index:idx_id,priority:1"`
Name7 string `gorm:"index:type"`
}
func TestParseIndex(t *testing.T) {
@ -78,6 +79,10 @@ func TestParseIndex(t *testing.T) {
Class: "UNIQUE",
Fields: []schema.IndexOption{{Field: &schema.Field{Name: "OID"}}},
},
"type": {
Name: "type",
Fields: []schema.IndexOption{{Field: &schema.Field{Name: "Name7"}}},
},
}
indices := user.ParseIndexes()