Skip to content

Commit

Permalink
[#289] Add coverage for eliminating default value tag (#290)
Browse files Browse the repository at this point in the history
* [#289] Add coverage for eliminating default value tag

* [#289] wip
  • Loading branch information
wookie0 authored Nov 21, 2024
1 parent 0d37bf2 commit f185f22
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,16 @@ func (m Migrator) AlterColumn(value interface{}, field string) error {
return err
}
} else {
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 {
if err := m.DB.Exec("ALTER TABLE ? ALTER COLUMN ? DROP DEFAULT", m.CurrentTable(stmt), clause.Column{Name: field.DBName}).Error; err != nil {
return err
}
}
} else if !field.HasDefaultValue {
// case - as-is column has default value and to-be column has no default value
// need to drop default
if err := m.DB.Exec("ALTER TABLE ? ALTER COLUMN ? DROP DEFAULT", m.CurrentTable(stmt), clause.Column{Name: field.DBName}).Error; err != nil {
return err
}
}
}
return nil
Expand Down

0 comments on commit f185f22

Please sign in to comment.