fix(bug): runMigrations not using named returned properly (#5913)
* return nil when no transaction is opened * use named return for retErr * add a comment
This commit is contained in:
1 parent
e000aeafcd
commit
b061cc544d
2 files changed
+6
-6
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user