Skip to content

Commit

Permalink
fix: db tx rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Nov 7, 2024
1 parent ef4fe29 commit 5e44136
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions aggsender/db/aggsender_db_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ func (a *AggSenderSQLStorage) SaveLastSentCertificate(ctx context.Context, certi
}
}()

if err := meddler.Insert(tx, "certificate_info", &certificate); err != nil {
if err = meddler.Insert(tx, "certificate_info", &certificate); err != nil {
return fmt.Errorf("error inserting certificate info: %w", err)
}
if err := tx.Commit(); err != nil {
if err = tx.Commit(); err != nil {
return err
}

Expand All @@ -150,10 +150,10 @@ func (a *AggSenderSQLStorage) DeleteCertificate(ctx context.Context, certificate
}
}()

if _, err := tx.Exec(`DELETE FROM certificate_info WHERE certificate_id = $1;`, certificateID); err != nil {
if _, err = tx.Exec(`DELETE FROM certificate_info WHERE certificate_id = $1;`, certificateID); err != nil {
return fmt.Errorf("error deleting certificate info: %w", err)
}
if err := tx.Commit(); err != nil {
if err = tx.Commit(); err != nil {
return err
}

Expand All @@ -176,11 +176,11 @@ func (a *AggSenderSQLStorage) UpdateCertificateStatus(ctx context.Context, certi
}
}()

if _, err := tx.Exec(`UPDATE certificate_info SET status = $1 WHERE certificate_id = $2;`,
if _, err = tx.Exec(`UPDATE certificate_info SET status = $1 WHERE certificate_id = $2;`,
certificate.Status, certificate.CertificateID); err != nil {
return fmt.Errorf("error updating certificate info: %w", err)
}
if err := tx.Commit(); err != nil {
if err = tx.Commit(); err != nil {
return err
}

Expand Down

0 comments on commit 5e44136

Please sign in to comment.