Open wedamija opened 1 day ago
Note: Most of the volume of this pr is migrations for tests - Mark them viewed so you can focus on the core part
Attention: Patch coverage is 86.48649%
with 10 lines
in your changes missing coverage. Please review.
:white_check_mark: All tests successful. No failed tests found.
Files with missing lines | Patch % | Lines |
---|---|---|
src/sentry/new_migrations/monkey/models.py | 74.19% | 8 Missing :warning: |
src/sentry/new_migrations/monkey/state.py | 94.11% | 2 Missing :warning: |
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.