Skip to content

Commit 02a1ea8

Browse files
committed
- considering column aliases for type checking in AlterColumn method
1 parent f8e422c commit 02a1ea8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

migrator.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,22 @@ func (m Migrator) AlterColumn(value interface{}, field string) error {
281281
}
282282

283283
fileType := clause.Expr{SQL: m.DataTypeOf(field)}
284+
// check for typeName and SQL name
285+
isSameType := true
284286
if fieldColumnType.DatabaseTypeName() != fileType.SQL {
287+
isSameType = false
288+
// if different, also check for aliases
289+
aliases := m.GetTypeAliases(fieldColumnType.DatabaseTypeName())
290+
for _, alias := range aliases {
291+
if strings.HasPrefix(fileType.SQL, alias) {
292+
isSameType = true
293+
break
294+
}
295+
}
296+
}
297+
298+
// not same, migrate
299+
if !isSameType {
285300
filedColumnAutoIncrement, _ := fieldColumnType.AutoIncrement()
286301
if field.AutoIncrement && filedColumnAutoIncrement { // update
287302
serialDatabaseType, _ := getSerialDatabaseType(fileType.SQL)

0 commit comments

Comments
 (0)