perf: check type

This commit is contained in:
a631807682 2022-09-22 12:06:54 +08:00
parent 311b852cfd
commit ca4fcb94c0
No known key found for this signature in database
GPG Key ID: 137D1D75522168AB

View File

@ -411,14 +411,20 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy
if !field.PrimaryKey { if !field.PrimaryKey {
// check type // check type
var isSameType bool var isSameType bool
if strings.HasPrefix(fullDataType, realDataType) {
isSameType = true
}
// check type aliases
if !isSameType {
aliases := m.DB.Migrator().GetTypeAliases(realDataType) aliases := m.DB.Migrator().GetTypeAliases(realDataType)
aliases = append(aliases, realDataType)
for _, alias := range aliases { for _, alias := range aliases {
if strings.HasPrefix(fullDataType, alias) { if strings.HasPrefix(fullDataType, alias) {
isSameType = true isSameType = true
break break
} }
} }
}
if !isSameType { if !isSameType {
alterColumn = true alterColumn = true