forked from getsentry/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(migrations): Allow m2m columns to be deleted without first making…
… them not null (getsentry#81209) These columns don't actually exist on the table, they just reference a bridging table.
- Loading branch information
Showing
7 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
55 changes: 55 additions & 0 deletions
55
...ions_apps/good_flow_delete_field_pending_with_not_null_m2m_app/migrations/0001_initial.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.db import migrations, models | ||
|
||
from sentry.db.models import FlexibleForeignKey | ||
from sentry.new_migrations.migrations import CheckedMigration | ||
|
||
|
||
class Migration(CheckedMigration): | ||
|
||
initial = True | ||
checked = False | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="OtherTable", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="M2MTable", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False)), | ||
( | ||
"alert_rule", | ||
FlexibleForeignKey( | ||
on_delete=models.deletion.CASCADE, | ||
to="good_flow_delete_field_pending_with_not_null_m2m_app.othertable", | ||
), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="TestTable", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False)), | ||
( | ||
"excluded_projects", | ||
models.ManyToManyField( | ||
through="good_flow_delete_field_pending_with_not_null_m2m_app.M2MTable", | ||
to="good_flow_delete_field_pending_with_not_null_m2m_app.othertable", | ||
), | ||
), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name="m2mtable", | ||
name="test_table", | ||
field=FlexibleForeignKey( | ||
on_delete=models.deletion.CASCADE, | ||
to="good_flow_delete_field_pending_with_not_null_m2m_app.testtable", | ||
), | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
...flow_delete_field_pending_with_not_null_m2m_app/migrations/0002_delete_without_pending.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from sentry.new_migrations.migrations import CheckedMigration | ||
from sentry.new_migrations.monkey.fields import SafeRemoveField | ||
from sentry.new_migrations.monkey.state import DeletionAction | ||
|
||
|
||
class Migration(CheckedMigration): | ||
dependencies = [ | ||
("good_flow_delete_field_pending_with_not_null_m2m_app", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
SafeRemoveField( | ||
model_name="testtable", | ||
name="excluded_projects", | ||
deletion_action=DeletionAction.MOVE_TO_PENDING, | ||
), | ||
] |
Empty file.
18 changes: 18 additions & 0 deletions
18
fixtures/safe_migrations_apps/good_flow_delete_field_pending_with_not_null_m2m_app/models.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.db import models | ||
|
||
from sentry.db.models import FlexibleForeignKey | ||
|
||
|
||
class OtherTable(models.Model): | ||
pass | ||
|
||
|
||
class M2MTable(models.Model): | ||
alert_rule = FlexibleForeignKey(OtherTable) | ||
test_table = FlexibleForeignKey( | ||
"good_flow_delete_field_pending_with_not_null_m2m_app.TestTable" | ||
) | ||
|
||
|
||
class TestTable(models.Model): | ||
excluded_projects = models.ManyToManyField(OtherTable, through=M2MTable) |
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