Skip to content

Commit

Permalink
fix(migrate): mark migrations as applied on error so the migration ca…
Browse files Browse the repository at this point in the history
…n be rolled back
  • Loading branch information
vmihailenco committed Dec 19, 2021
1 parent cd7a72e commit 8ce33fb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions migrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*Migra
migration := &group.Migrations[i]
migration.GroupID = group.ID

// Always mark migration as applied so the rollback has a chance to fix the database.
if err := m.MarkApplied(ctx, migration); err != nil {
return nil, err
}

if !cfg.nop && migration.Up != nil {
if err := migration.Up(ctx, m.db); err != nil {
return group, err
}
}

if err := m.MarkApplied(ctx, migration); err != nil {
return nil, err
}
}

return group, nil
Expand Down

0 comments on commit 8ce33fb

Please sign in to comment.