Fix issues updating triggers in non-atomic migrations #137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fields of trigger conditions can now have their types updated in non-atomic migrations.
Type: bug
@kekekekule I wanted to quickly address the issue at #136 and fix some things in your PR at #136. I thought it would be easiest to get this in another PR and deploy since I'm going to be away for a bit. I made sure you are the author of the commit, so you will get credit in the release. I also added you to the README as a contributor. Thanks for your contributions!
I believe that this individual operation still needs to be atomic, even if it's in a non-atomic migration. It's dangerous to drop a trigger outside of a transaction as it could lead to data loss for django-pghistory users and other use cases where triggers are necessary to be installed for data integrity.
I updated the code to still wrap the individual schema change in a transaction, ensuring that the trigger is dropped and re-created in that transaction. So, if your migration looks like this:
The separate alter statements won't be wrapped in a transaction. However, an individual alter statement may be temporarily wrapped in a transaction so that the trigger may be able to be safely dropped and re-created while the field is being altered.
I hope that makes sense. I made a failing test case first similar to the one you made, and I just used the normal
transaction.atomic
. I was incorrectly using aself.atomic
utility in the schema editor.If for any reason this doesn't address your use case, please let me know. I'm happy to revisit it. For now I plan to deploy this as the fix