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: Disable Foreign Key Checks During Restore #4444

Conversation

michael-genson
Copy link
Collaborator

@michael-genson michael-genson commented Oct 24, 2024

What type of PR is this?

(REQUIRED)

  • bug

What this PR does / why we need it:

(REQUIRED)

In certain instances, when restoring from backup, users may be restored before households. Since users have a fk constraint with households, this will fail, because the household doesn't exist yet.

This PR disables fk constraints during restore, then re-enables them. It uses a context manager to do this, so even if there's an error it will always be restored to its initial value.

Which issue(s) this PR fixes:

(REQUIRED)

Fixes #4433

Special notes for your reviewer:

(fill-in or delete this section)

Since it's possible to disable fk constraints manually (and they are disabled on sqlite by default) I made sure to preserve the existing setting rather than disable/re-enable. This approach ensures if fk constraints are disabled before Mealie touches them, then they stay disabled.

Testing

(fill-in or delete this section)

I used the backup related to #4433 to reproduce the issue locally on postgres, then observed that it's fixed now. I also added an anonymized backup to our test suite.

@michael-genson michael-genson changed the title fix: Disable Foreign Key Restraints During Restore fix: Disable Foreign Key Checks During Restore Oct 25, 2024
Copy link
Collaborator

@Kuchenpirat Kuchenpirat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good 👍

@Kuchenpirat Kuchenpirat enabled auto-merge (squash) October 29, 2024 12:39
@Kuchenpirat Kuchenpirat merged commit 8d1ce5c into mealie-recipes:mealie-next Oct 29, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Restoring mealie 2.0 does not work. Users are imported before households
2 participants