Skip to content

Commit

Permalink
fix: run a whole namespace migration as one transaction (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored Sep 30, 2021
1 parent 6811cd2 commit 142bd47
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions internal/persistence/sql/migrations/single_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func (m *toSingleTableMigrator) MigrateNamespace(ctx context.Context, n *namespa

var irrecoverableRTs ErrInvalidTuples

for done, page := false, 1; !done; {
if err := p.Transaction(ctx, func(ctx context.Context, _ *pop.Connection) error {
if err := p.Transaction(ctx, func(ctx context.Context, _ *pop.Connection) error {
for page := 1; ; page++ {
rs, hasNext, err := m.getOldRelationTuples(ctx, n, page, m.perPage)
if err != nil {
return err
Expand Down Expand Up @@ -223,16 +223,15 @@ func (m *toSingleTableMigrator) MigrateNamespace(ctx context.Context, n *namespa
return err
}
}

if !hasNext {
done = true
return nil
break
}

page++
return nil
}); err != nil {
return err
}

return nil
}); err != nil {
return err
}

if len(irrecoverableRTs) != 0 {
Expand Down

0 comments on commit 142bd47

Please sign in to comment.