Skip to content

Commit f185f22

Browse files
authored
[#289] Add coverage for eliminating default value tag (#290)
* [#289] Add coverage for eliminating default value tag * [#289] wip
1 parent 0d37bf2 commit f185f22

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

migrator.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,16 @@ func (m Migrator) AlterColumn(value interface{}, field string) error {
393393
return err
394394
}
395395
} else {
396-
if err := m.DB.Exec("ALTER TABLE ? ALTER COLUMN ? DROP DEFAULT", m.CurrentTable(stmt), clause.Column{Name: field.DBName}, clause.Expr{SQL: field.DefaultValue}).Error; err != nil {
396+
if err := m.DB.Exec("ALTER TABLE ? ALTER COLUMN ? DROP DEFAULT", m.CurrentTable(stmt), clause.Column{Name: field.DBName}).Error; err != nil {
397397
return err
398398
}
399399
}
400+
} else if !field.HasDefaultValue {
401+
// case - as-is column has default value and to-be column has no default value
402+
// need to drop default
403+
if err := m.DB.Exec("ALTER TABLE ? ALTER COLUMN ? DROP DEFAULT", m.CurrentTable(stmt), clause.Column{Name: field.DBName}).Error; err != nil {
404+
return err
405+
}
400406
}
401407
}
402408
return nil

0 commit comments

Comments
 (0)