Skip to content

Commit b1bdb34

Browse files
Backport of fix(bug): runMigrations not using named returned properly into release/0.19.x (#5914)
* backport of commit f44e2c1 * backport of commit 98be3cb * backport of commit d4ece2d --------- Co-authored-by: Sorawis Nilparuk <[email protected]>
1 parent 4bb3713 commit b1bdb34

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

internal/db/schema/internal/postgres/postgres.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ func (p *Postgres) RollbackRun(ctx context.Context) error {
208208
defer func() {
209209
p.tx = nil
210210
}()
211+
212+
// p.tx is set to nil after the commit so if p.tx == nil, we assume that the transaction has
213+
// already been committed and do nothing
211214
if p.tx == nil {
212-
return errors.New(ctx, errors.MigrationIntegrity, op, "no pending transaction")
215+
return nil
213216
}
214217
if err := p.tx.Rollback(); err != nil {
215218
if errors.Is(err, sql.ErrTxDone) {

internal/db/schema/manager.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,9 @@ func (b *Manager) ApplyMigrations(ctx context.Context) ([]RepairLog, error) {
243243
// runMigrations passes migration queries to a database driver and manages
244244
// the version and dirty bit. Cancellation or deadline/timeout is managed
245245
// through the passed in context.
246-
func (b *Manager) runMigrations(ctx context.Context, p *provider.Provider) ([]RepairLog, error) {
246+
func (b *Manager) runMigrations(ctx context.Context, p *provider.Provider) (logEntries []RepairLog, retErr error) {
247247
const op = "schema.(Manager).runMigrations"
248248

249-
var logEntries []RepairLog
250-
var retErr error
251-
252249
if startErr := b.driver.StartRun(ctx); startErr != nil {
253250
return nil, errors.Wrap(ctx, startErr, op)
254251
}
@@ -312,5 +309,5 @@ func (b *Manager) runMigrations(ctx context.Context, p *provider.Provider) ([]Re
312309
return nil, errors.Wrap(ctx, err, op)
313310
}
314311

315-
return logEntries, retErr
312+
return logEntries, nil
316313
}

0 commit comments

Comments
 (0)