Skip to content

Commit

Permalink
feat: Safety option for skip column changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mittwillson committed Sep 28, 2021
1 parent 9e50088 commit 61f417b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Config struct {
DisableForeignKeyConstraintWhenMigrating bool
// DisableNestedTransaction disable nested transaction
DisableNestedTransaction bool
// SafetyAutoMigration disable columns alter when it exists
SafetyAutoMigration bool
// AllowGlobalUpdate allow global update
AllowGlobalUpdate bool
// QueryFields executes the SQL query with all fields of the table
Expand Down
2 changes: 2 additions & 0 deletions migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (m Migrator) AutoMigrate(values ...interface{}) error {
if err := tx.Migrator().AddColumn(value, field.DBName); err != nil {
return err
}
} else if m.DB.SafetyAutoMigration {
// skip MigrationColumn
} else if err := m.DB.Migrator().MigrateColumn(value, field, foundColumn); err != nil {
// found, smart migrate
return err
Expand Down

0 comments on commit 61f417b

Please sign in to comment.