From b1bdb3442b82bb582012e00599ec387f130f5b9c Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-boundary <82989682+hc-github-team-secure-boundary@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:39:17 -0400 Subject: [PATCH] Backport of fix(bug): runMigrations not using named returned properly into release/0.19.x (#5914) * backport of commit f44e2c1df68b52ffd8d6bd3156dce4a89d516c2b * backport of commit 98be3cbf6fd3d12a0abc266ec0aef903ba74f103 * backport of commit d4ece2dcc34dafd917b1bb7ca5c75fd61453f759 --------- Co-authored-by: Sorawis Nilparuk --- internal/db/schema/internal/postgres/postgres.go | 5 ++++- internal/db/schema/manager.go | 7 ++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/db/schema/internal/postgres/postgres.go b/internal/db/schema/internal/postgres/postgres.go index 7351981d31..afc4daeeaa 100644 --- a/internal/db/schema/internal/postgres/postgres.go +++ b/internal/db/schema/internal/postgres/postgres.go @@ -208,8 +208,11 @@ func (p *Postgres) RollbackRun(ctx context.Context) error { defer func() { p.tx = nil }() + + // p.tx is set to nil after the commit so if p.tx == nil, we assume that the transaction has + // already been committed and do nothing if p.tx == nil { - return errors.New(ctx, errors.MigrationIntegrity, op, "no pending transaction") + return nil } if err := p.tx.Rollback(); err != nil { if errors.Is(err, sql.ErrTxDone) { diff --git a/internal/db/schema/manager.go b/internal/db/schema/manager.go index 9f2426085a..000c8aca93 100644 --- a/internal/db/schema/manager.go +++ b/internal/db/schema/manager.go @@ -243,12 +243,9 @@ func (b *Manager) ApplyMigrations(ctx context.Context) ([]RepairLog, error) { // runMigrations passes migration queries to a database driver and manages // the version and dirty bit. Cancellation or deadline/timeout is managed // through the passed in context. -func (b *Manager) runMigrations(ctx context.Context, p *provider.Provider) ([]RepairLog, error) { +func (b *Manager) runMigrations(ctx context.Context, p *provider.Provider) (logEntries []RepairLog, retErr error) { const op = "schema.(Manager).runMigrations" - var logEntries []RepairLog - var retErr error - if startErr := b.driver.StartRun(ctx); startErr != nil { return nil, errors.Wrap(ctx, startErr, op) } @@ -312,5 +309,5 @@ func (b *Manager) runMigrations(ctx context.Context, p *provider.Provider) ([]Re return nil, errors.Wrap(ctx, err, op) } - return logEntries, retErr + return logEntries, nil }