Skip to content

Commit

Permalink
fix: change rollback to always record migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 25, 2022
1 parent dca5db2 commit d6e6e55
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions chmigrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,16 @@ func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*Migr
for i := len(lastGroup.Migrations) - 1; i >= 0; i-- {
migration := &lastGroup.Migrations[i]

// Always mark migration as unapplied to match migrate behavior.
if err := m.MarkUnapplied(ctx, migration); err != nil {
return nil, err
}

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

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

return lastGroup, nil
Expand Down

0 comments on commit d6e6e55

Please sign in to comment.