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 add_check_constraint when raising an error in safe mode #272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chaadow
Copy link
Contributor

@chaadow chaadow commented Sep 1, 2024

Followup to #271

When adding a CHECK constraint and safe mode is enabled:

  • we add a NOT VALID check constraint
  • then commit the transaction
  • and finally validate the check constraint in another migration.

If the validation step fails, this leaves a NOT VALID check constraint in the database.
If we retry after having cleaned up the database, the creation of the NOT VALID check constraint will fail because it will already be in the DB.

This commit makes the migration safely retriable by checking if said check constraint already exists, and if so, skips its creation again.

@chaadow chaadow force-pushed the fix_safe_default_check_constraint branch from 2e34975 to 35feb0d Compare September 1, 2024 16:19
Followup to ankane#271

When adding a CHECK constraint and safe mode is enabled:

- we add a NOT VALID check constraint
- then commit the transaction
- and finally validate the check constraint in another migration.

If the validation step fails, this leaves a NOT VALID check constraint
in the database.
If we retry after having cleaned up the database, the creation of the
NOT VALID check constraint will fail because it will already be in the
DB.

This commit makes the migration safely retriable by checking if said
check constraint already exists, and if so, skips its creation again.
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 participant