-
Notifications
You must be signed in to change notification settings - Fork 12k
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
SQLStore: Fix PostgreSQL failure to create organisation for first time #21648
Conversation
|
||
// sync primary key sequence of org table | ||
if _, err := sess.Exec("SELECT setval('org_id_seq', (SELECT max(id)+1 FROM org));"); err != nil { | ||
return fmt.Errorf("Failed to sync primary key for org table") |
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 seems to follow the error pattern in the file, but I wonder:
- Why not return the error if an error?
- Regardless of what is done with the error, should the contents of sess.Exec's err be wrapped into the message so the reason is logged?
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.
good points, I will fix it!
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.
Yeah, wrapping the error sounds like the thing to do for me as well :)
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 AFAICT, apart from the error that should get wrapped.
|
||
// sync primary key sequence of org table | ||
if _, err := sess.Exec("SELECT setval('org_id_seq', (SELECT max(id)+1 FROM org));"); err != nil { | ||
return fmt.Errorf("Failed to sync primary key for org table") |
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.
Yeah, wrapping the error sounds like the thing to do for me as well :)
Co-Authored-By: Arve Knudsen <arve.knudsen@gmail.com>
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.
LGTM!
What this PR does / why we need it:
Grafana explicitly sets the org id when creates the main organisation. However, this does not work nicely with PostgresSQL because it seems that the primary key sequence is only evaluated when the id field is not set. This fix adds a hook for syncing the sequence for the org table after inserts.
Which issue(s) this PR fixes:
Fixes #18628
Special notes for your reviewer: