Backport of fix(bug): runMigrations not using named returned properly into release/0.19.x (#5914)

* backport of commit f44e2c1df6

* backport of commit 98be3cbf6f

* backport of commit d4ece2dcc3

---------

Co-authored-by: Sorawis Nilparuk <sorawis.nilparuk@hashicorp.com>
pull/5921/head v0.19.3
hc-github-team-secure-boundary 8 months ago committed by GitHub
parent 4bb3713ef0
commit b1bdb3442b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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) {

@ -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
}

Loading…
Cancel
Save