Browse Source

ref(escalating-issues): Remove foreign key constraint in GroupForecast (#47578)

Step 1 of deleting the GroupForecast table

WOR-2966
Jodi Jang 1 year ago
parent
commit
921f272981

+ 1 - 1
migrations_lockfile.txt

@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
 will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0421_rule_set_null_owner_deleted
+sentry: 0422_remove_group_forecast_fk_constraint
 social_auth: 0001_initial

+ 38 - 0
src/sentry/migrations/0422_remove_group_forecast_fk_constraint.py

@@ -0,0 +1,38 @@
+# Generated by Django 2.2.28 on 2023-04-18 19:52
+
+import django.db.models.deletion
+from django.db import migrations
+
+import sentry.db.models.fields.foreignkey
+from sentry.new_migrations.migrations import CheckedMigration
+
+
+class Migration(CheckedMigration):
+    # This flag is used to mark that a migration shouldn't be automatically run in production. For
+    # the most part, this should only be used for operations where it's safe to run the migration
+    # after your code has deployed. So this should not be used for most operations that alter the
+    # schema of a table.
+    # Here are some things that make sense to mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that they can
+    #   be monitored and not block the deploy for a long period of time while they run.
+    # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
+    #   have ops run this and not block the deploy. Note that while adding an index is a schema
+    #   change, it's completely safe to run the operation after the code has deployed.
+    is_dangerous = False
+
+    dependencies = [
+        ("sentry", "0421_rule_set_null_owner_deleted"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="groupforecast",
+            name="group",
+            field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                db_constraint=False,
+                on_delete=django.db.models.deletion.CASCADE,
+                to="sentry.Group",
+                unique=True,
+            ),
+        ),
+    ]

+ 1 - 1
src/sentry/models/groupforecast.py

@@ -23,7 +23,7 @@ class GroupForecast(Model):
 
     __include_in_export__ = False
 
-    group = FlexibleForeignKey("sentry.Group", unique=True)
+    group = FlexibleForeignKey("sentry.Group", unique=True, db_constraint=False)
     forecast = ArrayField(of=BoundedPositiveIntegerField, null=True)
     date_added = models.DateTimeField(default=timezone.now)