Skip to content

Commit

Permalink
- considering column aliases for type checking in AlterColumn method
Browse files Browse the repository at this point in the history
  • Loading branch information
rwrz committed Nov 2, 2022
1 parent f8e422c commit 02a1ea8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions migrator.go
Expand Up @@ -281,7 +281,22 @@ func (m Migrator) AlterColumn(value interface{}, field string) error {
}

fileType := clause.Expr{SQL: m.DataTypeOf(field)}
// check for typeName and SQL name
isSameType := true
if fieldColumnType.DatabaseTypeName() != fileType.SQL {
isSameType = false
// if different, also check for aliases
aliases := m.GetTypeAliases(fieldColumnType.DatabaseTypeName())
for _, alias := range aliases {
if strings.HasPrefix(fileType.SQL, alias) {
isSameType = true
break
}
}
}

// not same, migrate
if !isSameType {
filedColumnAutoIncrement, _ := fieldColumnType.AutoIncrement()
if field.AutoIncrement && filedColumnAutoIncrement { // update
serialDatabaseType, _ := getSerialDatabaseType(fileType.SQL)
Expand Down

0 comments on commit 02a1ea8

Please sign in to comment.