mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-01 00:17:24 +00:00
fix: verboser logging on sql err (#412)
* fix(eventstore): improve insert statement * fix: verbose logging on error * fix: simplify insertEvents
This commit is contained in:
parent
0721acf605
commit
e8f3868100
@ -68,26 +68,19 @@ func precondtion(tx *sql.Tx, aggregate *models.Aggregate) error {
|
|||||||
|
|
||||||
func insertEvents(stmt *sql.Stmt, previousSequence Sequence, events []*models.Event) error {
|
func insertEvents(stmt *sql.Stmt, previousSequence Sequence, events []*models.Event) error {
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
rows, err := stmt.Query(event.Type, event.AggregateType, event.AggregateID, event.AggregateVersion, event.CreationDate, Data(event.Data), event.EditorUser, event.EditorService, event.ResourceOwner, previousSequence,
|
err := stmt.QueryRow(event.Type, event.AggregateType, event.AggregateID, event.AggregateVersion, event.CreationDate, Data(event.Data), event.EditorUser, event.EditorService, event.ResourceOwner, previousSequence,
|
||||||
event.AggregateType, event.AggregateID, previousSequence, previousSequence)
|
event.AggregateType, event.AggregateID, previousSequence, previousSequence).Scan(&event.ID, &previousSequence, &event.CreationDate)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Log("SQL-EXA0q").WithError(err).Info("query failed")
|
logging.LogWithFields("SQL-IP3js",
|
||||||
|
"aggregate", event.AggregateType,
|
||||||
|
"id", event.AggregateID,
|
||||||
|
"previousSequence", previousSequence,
|
||||||
|
"aggregateId", event.AggregateID,
|
||||||
|
"aggregateType", event.AggregateType,
|
||||||
|
"eventType", event.Type).WithError(err).Info("query failed")
|
||||||
return caos_errs.ThrowInternal(err, "SQL-SBP37", "unable to create event")
|
return caos_errs.ThrowInternal(err, "SQL-SBP37", "unable to create event")
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
rowInserted := false
|
|
||||||
for rows.Next() {
|
|
||||||
rowInserted = true
|
|
||||||
err = rows.Scan(&event.ID, &previousSequence, &event.CreationDate)
|
|
||||||
logging.Log("SQL-rAvLD").OnError(err).Info("unable to scan result into event")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !rowInserted {
|
|
||||||
logging.LogWithFields("SQL-5aATu", "aggregate", event.AggregateType, "id", event.AggregateID).Info("wrong sequence")
|
|
||||||
return caos_errs.ThrowAlreadyExists(nil, "SQL-GKcAa", "wrong sequence")
|
|
||||||
}
|
|
||||||
|
|
||||||
event.Sequence = uint64(previousSequence)
|
event.Sequence = uint64(previousSequence)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user