-
-
Notifications
You must be signed in to change notification settings - Fork 916
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 migration problems with initially deferred and not null constraints #5533
Conversation
Executes `SET CONSTRAINTS xyz IMMEDIATE;` before `CREATE INDEX` and `ALTER COLUMN` that otherwise fail because of "pending trigger events".
ALTER TABLE post | ||
ALTER COLUMN instance_id SET NOT NULL; |
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.
Dopped the DEFAULT 0
here.
@@ -37,6 +37,10 @@ ALTER TABLE comment | |||
DROP COLUMN report_count, | |||
DROP COLUMN unresolved_report_count; | |||
|
|||
SET CONSTRAINTS comment_aggregates_comment_id_fkey IMMEDIATE; |
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.
It seems like these SET CONSTRAINTS IMMEDIATE
statements are immediately overwritten and could be removed.
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.
https://www.postgresql.org/docs/current/sql-set-constraints.html:
SET CONSTRAINTS — set constraint check timing for the current transaction
^ only the current transaction
When SET CONSTRAINTS changes the mode of a constraint from DEFERRED to IMMEDIATE, the new mode takes effect retroactively: any outstanding data modifications that would have been checked at the end of the transaction are instead checked during the execution of the SET CONSTRAINTS command.
Changing the constraint back to DEFERRED
is probably only necessary when the same transaction later again updates the table or the referenced table, but should have little impact if it doesn't.
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 catch, thx.
@dullbananas should also have a look as there might be others.
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. I can't easily tell if there's more places in the migrations that need this. That should be determined by tests (I will open an issue).
Thanks! |
Executes
SET CONSTRAINTS xyz IMMEDIATE;
beforeCREATE INDEX
andALTER COLUMN
that otherwise fail because of "pending trigger events".These errors only show up when the tables hold data during the migrations.
Fixes #5531