-
Notifications
You must be signed in to change notification settings - Fork 113
Fix hardcoded postgres role on set_updated_at function #306
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,5 @@ | ||||||||||||||||||||||||||
| -- Migration 0012 hardcoded "postgres" as the function owner, which fails on | ||||||||||||||||||||||||||
| -- PostgreSQL installations where that role does not exist (e.g. managed cloud | ||||||||||||||||||||||||||
| -- databases). Re-assign ownership to the role executing the migration so it | ||||||||||||||||||||||||||
| -- works in any environment. | ||||||||||||||||||||||||||
| ALTER FUNCTION set_updated_at() OWNER TO CURRENT_USER; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| ALTER FUNCTION set_updated_at() OWNER TO CURRENT_USER; | |
| ALTER FUNCTION stripe.set_updated_at() OWNER TO CURRENT_USER; |
Copilot
AI
Mar 31, 2026
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.
ALTER FUNCTION ... OWNER TO ... will fail unless the migration role is either a superuser or the current owner of set_updated_at(). If 0012 ran as a different role (or set the owner to a role the migrator is not a member of), this migration can abort and stop all subsequent migrations. Consider making this change tolerant to insufficient privileges (e.g., run inside a DO block that catches insufficient_privilege / undefined_function and no-ops) so migrations remain runnable across role changes and partial installs.
| ALTER FUNCTION set_updated_at() OWNER TO CURRENT_USER; | |
| DO $$ | |
| BEGIN | |
| ALTER FUNCTION set_updated_at() OWNER TO CURRENT_USER; | |
| EXCEPTION | |
| WHEN insufficient_privilege OR undefined_function THEN | |
| -- If we don't own the function or it doesn't exist, ignore and continue. | |
| NULL; | |
| END; | |
| $$; |
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.
The header comment says this “works in any environment”, but on clusters where role
postgresdoesn’t exist the failure occurs in migration 0012 andpg-node-migrationsstops after rolling back 0012, so 0043 is never reached. Please clarify the comment (and/or PR description) about what scenarios this migration actually fixes vs. which still require a separate remediation path (fresh installs on non-postgressystems).