-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(backend): upsert annotations #1508
Conversation
size-limit report 📦
|
Codecov ReportBase: 65.81% // Head: 66.31% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1508 +/- ##
==========================================
+ Coverage 65.81% 66.31% +0.51%
==========================================
Files 139 139
Lines 4755 4755
Branches 1288 1288
==========================================
+ Hits 3129 3153 +24
+ Misses 1621 1597 -24
Partials 5 5
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
if tx.Where(model.CreateAnnotation{ | ||
AppName: params.AppName, | ||
Timestamp: params.Timestamp, | ||
}).Updates(&u).RowsAffected == 0 { | ||
return &u, tx.Create(&u).Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a working solution, though I used slightly different approach in past to avoid conflicts – you may find it useful: https://gorm.io/docs/create.html#Upsert-x2F-On-Conflict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe no conflict will be generated since I haven't added a unique constraint on the columns /facepalm https://github.com/pyroscope-io/pyroscope/blob/main/pkg/sqlstore/migrations/migrations.go#L118-L119
Hopefully it will be solved via #1509
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see – thank you for the explanation!
Closes #1507