-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(migrations): Add in SafeDeleteModel migration operation
#81063
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
Conversation
|
Note: Most of the volume of this pr is migrations for tests - Mark them viewed so you can focus on the core part |
This builds on #81063 This adds in `SafeDeleteColumn`, which works the same way as `SafeDeleteModel`, except on database columns. It performs checks that the column doesn't have a db constraint set, and also that it is either nullable or has a db_default set. Similarly to `SafeDeleteModel` we still need to be careful to make sure that the pending deletion merges and deploys first, and then the real deletion.
This uses the new operations from getsentry/sentry#81063 getsentry/sentry#81098
This builds on #81063 This adds in `SafeDeleteColumn`, which works the same way as `SafeDeleteModel`, except on database columns. It performs checks that the column doesn't have a db constraint set, and also that it is either nullable or has a db_default set. Similarly to `SafeDeleteModel` we still need to be careful to make sure that the pending deletion merges and deploys first, and then the real deletion.
This adds in the `SafeDeleteModel` operation. Most of this pr is testing and monkeypatching Django migrations to be able to hook this in. `SafeDeleteModel` allows us to delete models in two steps without using custom sql. If accepts a deletion_action parameter, which must be passed, and can be either MOVE_TO_PENDING or DELETE. MOVE_TO_PENDING checks that there are no constraints on the table and removes the table from the migation state. We keep track of pending models separately, so that they can be deleted in the next step. DELETE runs the delete command on the database. It is able to still reference the model since we keep track of this in our patched state. If delete is run before MOVE_TO_PENDING then the migration will be rejected. Some care is still needed when using these - we still have to ensure that the PENDING migration runs and fully deploys before the DELETE does. But other than that this reduces the manual error prone sql work around this process a lot.
a3cfac3 to
e187edf
Compare
This builds on #81063 This adds in `SafeDeleteColumn`, which works the same way as `SafeDeleteModel`, except on database columns. It performs checks that the column doesn't have a db constraint set, and also that it is either nullable or has a db_default set. Similarly to `SafeDeleteModel` we still need to be careful to make sure that the pending deletion merges and deploys first, and then the real deletion.
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #81063 +/- ##
=======================================
Coverage 80.33% 80.34%
=======================================
Files 7223 7225 +2
Lines 320085 320155 +70
Branches 20778 20778
=======================================
+ Hits 257156 257218 +62
- Misses 62536 62544 +8
Partials 393 393 |
markstory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
This builds on #81063 This adds in `SafeDeleteColumn`, which works the same way as `SafeDeleteModel`, except on database columns. It performs checks that the column doesn't have a db constraint set, and also that it is either nullable or has a db_default set. Similarly to `SafeDeleteModel` we still need to be careful to make sure that the pending deletion merges and deploys first, and then the real deletion.
This uses the new operations from getsentry/sentry#81063 getsentry/sentry#81098
This builds on #81063 This adds in `SafeDeleteColumn`, which works the same way as `SafeDeleteModel`, except on database columns. It performs checks that the column doesn't have a db constraint set, and also that it is either nullable or has a db_default set. Similarly to `SafeDeleteModel` we still need to be careful to make sure that the pending deletion merges and deploys first, and then the real deletion.
This uses the new operations from getsentry/sentry#81063 getsentry/sentry#81098
This adds in the `SafeDeleteModel` operation. Most of this pr is testing and monkeypatching Django migrations to be able to hook this in. `SafeDeleteModel` allows us to delete models in two steps without using custom sql. If accepts a deletion_action parameter, which must be passed, and can be either MOVE_TO_PENDING or DELETE. MOVE_TO_PENDING checks that there are no constraints on the table and removes the table from the migation state. We keep track of pending models separately, so that they can be deleted in the next step. DELETE runs the delete command on the database. It is able to still reference the model since we keep track of this in our patched state. If delete is run before MOVE_TO_PENDING then the migration will be rejected. Some care is still needed when using these - we still have to ensure that the PENDING migration runs and fully deploys before the DELETE does. But other than that this reduces the manual error prone sql work around this process a lot. <!-- Describe your PR here. -->
This builds on #81063 This adds in `SafeDeleteColumn`, which works the same way as `SafeDeleteModel`, except on database columns. It performs checks that the column doesn't have a db constraint set, and also that it is either nullable or has a db_default set. Similarly to `SafeDeleteModel` we still need to be careful to make sure that the pending deletion merges and deploys first, and then the real deletion.
This adds in the `SafeDeleteModel` operation. Most of this pr is testing and monkeypatching Django migrations to be able to hook this in. `SafeDeleteModel` allows us to delete models in two steps without using custom sql. If accepts a deletion_action parameter, which must be passed, and can be either MOVE_TO_PENDING or DELETE. MOVE_TO_PENDING checks that there are no constraints on the table and removes the table from the migation state. We keep track of pending models separately, so that they can be deleted in the next step. DELETE runs the delete command on the database. It is able to still reference the model since we keep track of this in our patched state. If delete is run before MOVE_TO_PENDING then the migration will be rejected. Some care is still needed when using these - we still have to ensure that the PENDING migration runs and fully deploys before the DELETE does. But other than that this reduces the manual error prone sql work around this process a lot. <!-- Describe your PR here. -->
This builds on #81063 This adds in `SafeDeleteColumn`, which works the same way as `SafeDeleteModel`, except on database columns. It performs checks that the column doesn't have a db constraint set, and also that it is either nullable or has a db_default set. Similarly to `SafeDeleteModel` we still need to be careful to make sure that the pending deletion merges and deploys first, and then the real deletion.
This adds in the `SafeDeleteModel` operation. Most of this pr is testing and monkeypatching Django migrations to be able to hook this in. `SafeDeleteModel` allows us to delete models in two steps without using custom sql. If accepts a deletion_action parameter, which must be passed, and can be either MOVE_TO_PENDING or DELETE. MOVE_TO_PENDING checks that there are no constraints on the table and removes the table from the migation state. We keep track of pending models separately, so that they can be deleted in the next step. DELETE runs the delete command on the database. It is able to still reference the model since we keep track of this in our patched state. If delete is run before MOVE_TO_PENDING then the migration will be rejected. Some care is still needed when using these - we still have to ensure that the PENDING migration runs and fully deploys before the DELETE does. But other than that this reduces the manual error prone sql work around this process a lot. <!-- Describe your PR here. -->
This builds on #81063 This adds in `SafeDeleteColumn`, which works the same way as `SafeDeleteModel`, except on database columns. It performs checks that the column doesn't have a db constraint set, and also that it is either nullable or has a db_default set. Similarly to `SafeDeleteModel` we still need to be careful to make sure that the pending deletion merges and deploys first, and then the real deletion.
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
This adds in the
SafeDeleteModeloperation. Most of this pr is testing and monkeypatching Django migrations to be able to hook this in.SafeDeleteModelallows us to delete models in two steps without using custom sql. If accepts a deletion_action parameter, which must be passed, and can be either MOVE_TO_PENDING or DELETE.MOVE_TO_PENDING checks that there are no constraints on the table and removes the table from the migation state. We keep track of pending models separately, so that they can be deleted in the next step.
DELETE runs the delete command on the database. It is able to still reference the model since we keep track of this in our patched state. If delete is run before MOVE_TO_PENDING then the migration will be rejected.
Some care is still needed when using these - we still have to ensure that the PENDING migration runs and fully deploys before the DELETE does. But other than that this reduces the manual error prone sql work around this process a lot.