-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unstable temporary check constraint in case of an error
When changing a column null value from true to false (namely, the column becomes NOT NULL) 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. The issue arises when the validation of check constraint fails. This leaves an invalid check constraint in the database and it is NOT dropped in a cleanup phase. After making sure that all values are NOT NULL), we then retry to run `rails db:migrate`. However this fails, because, since the check constraint already exists, it will result in an error raised stating that said check constraint **already** exists. This commit fixes the issue in both ways: - Firstly, if we're already in this unstable state of a NOT VALID check constraint already existing in the database, we avoid the recreation of the constraint and simply ignore this step - Secondly, in case the check validation fails, we rescue the exception and execute the drop of the check constraint to avoid leaving the database in an unstable state.
- Loading branch information
Showing
4 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters