Skip to content

Commit

Permalink
Rollback operation on Start failure
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-farries committed Aug 31, 2023
1 parent ac990e6 commit 3d3b69c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/roll/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package roll

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -40,7 +41,11 @@ func (m *Roll) Start(ctx context.Context, migration *migrations.Migration) error
for _, op := range migration.Operations {
err := op.Start(ctx, m.pgConn, m.state.Schema(), newSchema)
if err != nil {
return fmt.Errorf("unable to execute start operation: %w", err)
errRollback := m.Rollback(ctx)

return errors.Join(
fmt.Errorf("unable to execute start operation: %w", err),
errRollback)
}

if _, ok := op.(migrations.RequiresSchemaRefreshOperation); ok {
Expand Down

0 comments on commit 3d3b69c

Please sign in to comment.