mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
fix: add RollbackUnlessCommitted for gorm transactions (#7197)
This commit is contained in:
parent
7c592ce638
commit
3d3264eb8f
@ -57,6 +57,7 @@ func PrepareSearchQuery(table string, request SearchRequest) func(db *gorm.DB, r
|
||||
if err := query.Commit().Error; err != nil {
|
||||
logging.OnError(err).Info("commit failed")
|
||||
}
|
||||
query.RollbackUnlessCommitted()
|
||||
}()
|
||||
|
||||
query = query.Count(&count)
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
@ -28,6 +29,7 @@ func PrepareGetByQuery(table string, queries ...SearchQuery) func(db *gorm.DB, r
|
||||
if err := tx.Commit().Error; err != nil {
|
||||
logging.OnError(err).Info("commit failed")
|
||||
}
|
||||
tx.RollbackUnlessCommitted()
|
||||
}()
|
||||
|
||||
err := tx.Take(res).Error
|
||||
@ -46,6 +48,7 @@ func PrepareBulkSave(table string) func(db *gorm.DB, objects ...interface{}) err
|
||||
return func(db *gorm.DB, objects ...interface{}) error {
|
||||
db = db.Table(table)
|
||||
db = db.Begin()
|
||||
defer db.RollbackUnlessCommitted()
|
||||
if err := db.Error; err != nil {
|
||||
return zerrors.ThrowInternal(err, "REPOS-Fl0Is", "unable to begin")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user