Skip to content

Commit 6055dc9

Browse files
wedamijaharshithadurai
authored andcommitted
feat(migrations): Add in SafeDeleteColumn migration operation (#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.
1 parent 9811390 commit 6055dc9

File tree

44 files changed

+753
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+753
-12
lines changed

fixtures/safe_migrations_apps/bad_flow_delete_field_double_pending_app/__init__.py

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 3.1 on 2019-09-22 21:47
2+
3+
from django.db import migrations, models
4+
5+
from sentry.new_migrations.migrations import CheckedMigration
6+
7+
8+
class Migration(CheckedMigration):
9+
10+
initial = True
11+
12+
dependencies = []
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name="TestTable",
17+
fields=[
18+
(
19+
"id",
20+
models.AutoField(
21+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
22+
),
23+
),
24+
("field", models.IntegerField(null=True)),
25+
],
26+
),
27+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from sentry.new_migrations.migrations import CheckedMigration
2+
from sentry.new_migrations.monkey.fields import SafeRemoveField
3+
from sentry.new_migrations.monkey.state import DeletionAction
4+
5+
6+
class Migration(CheckedMigration):
7+
8+
dependencies = [
9+
("bad_flow_delete_field_double_pending_app", "0001_initial"),
10+
]
11+
12+
operations = [
13+
SafeRemoveField(
14+
model_name="testtable",
15+
name="field",
16+
deletion_action=DeletionAction.MOVE_TO_PENDING,
17+
),
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from sentry.new_migrations.migrations import CheckedMigration
2+
from sentry.new_migrations.monkey.fields import SafeRemoveField
3+
from sentry.new_migrations.monkey.state import DeletionAction
4+
5+
6+
class Migration(CheckedMigration):
7+
8+
dependencies = [
9+
("bad_flow_delete_field_double_pending_app", "0002_delete_pending"),
10+
]
11+
12+
operations = [
13+
SafeRemoveField(
14+
model_name="testtable",
15+
name="field",
16+
deletion_action=DeletionAction.MOVE_TO_PENDING,
17+
),
18+
]

fixtures/safe_migrations_apps/bad_flow_delete_field_double_pending_app/migrations/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.db import models
2+
3+
4+
class TestTable(models.Model):
5+
field = models.IntegerField(default=0, null=False)

fixtures/safe_migrations_apps/bad_flow_delete_field_pending_with_fk_constraint_app/__init__.py

Whitespace-only changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import django
2+
from django.db import migrations, models
3+
4+
import sentry
5+
from sentry.new_migrations.migrations import CheckedMigration
6+
7+
8+
class Migration(CheckedMigration):
9+
10+
initial = True
11+
12+
dependencies = []
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name="FkTable",
17+
fields=[
18+
(
19+
"id",
20+
models.AutoField(
21+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
22+
),
23+
),
24+
],
25+
),
26+
migrations.CreateModel(
27+
name="TestTable",
28+
fields=[
29+
(
30+
"id",
31+
models.AutoField(
32+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
33+
),
34+
),
35+
(
36+
"fk_table",
37+
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
38+
on_delete=django.db.models.deletion.CASCADE,
39+
to="bad_flow_delete_field_pending_with_fk_constraint_app.fktable",
40+
db_index=False,
41+
),
42+
),
43+
],
44+
),
45+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from sentry.new_migrations.migrations import CheckedMigration
2+
from sentry.new_migrations.monkey.fields import SafeRemoveField
3+
from sentry.new_migrations.monkey.state import DeletionAction
4+
5+
6+
class Migration(CheckedMigration):
7+
atomic = False
8+
9+
dependencies = [
10+
("bad_flow_delete_field_pending_with_fk_constraint_app", "0001_initial"),
11+
]
12+
13+
operations = [
14+
SafeRemoveField(
15+
model_name="testtable",
16+
name="fk_table",
17+
deletion_action=DeletionAction.MOVE_TO_PENDING,
18+
),
19+
]

fixtures/safe_migrations_apps/bad_flow_delete_field_pending_with_fk_constraint_app/migrations/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)