Skip to content
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

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

matc-pub
Copy link
Contributor

Executes SET CONSTRAINTS xyz IMMEDIATE; before CREATE INDEX and ALTER COLUMN that otherwise fail because of "pending trigger events".

These errors only show up when the tables hold data during the migrations.

Fixes #5531

Executes `SET CONSTRAINTS xyz IMMEDIATE;` before `CREATE INDEX` and
`ALTER COLUMN` that otherwise fail because of "pending trigger events".
Comment on lines +81 to +82
ALTER TABLE post
ALTER COLUMN instance_id SET NOT NULL;
Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@dessalines dessalines left a 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.

Copy link
Collaborator

@dullbananas dullbananas left a 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).

@Nutomic Nutomic merged commit 3664f98 into LemmyNet:main Mar 25, 2025
1 check passed
@Nutomic
Copy link
Member

Nutomic commented Mar 25, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[1.0]: Migration remove-aggregate-tables fails on voyager.lemmy.ml
4 participants