Browse Source

chore(migrations) Rework migration that fails because of removed model (#54781)

The PagerDutyService model has been removed from the application code as
we are no longer using it. Because the table has been removed it doesn't
resolve to a silo in split db scenarios.

I don't love this solution but it feels better than re-instating the
PagerDutyService model and hoping that no one uses it.
Mark Story 1 year ago
parent
commit
1c169b257a

+ 7 - 2
src/sentry/migrations/0517_backfill_pagerdutyservices_into_org_integrations.py

@@ -1,4 +1,4 @@
-from django.db import migrations, router, transaction
+from django.db import ProgrammingError, migrations, router, transaction
 
 from sentry.new_migrations.migrations import CheckedMigration
 from sentry.utils.query import RangeQuerySetWrapper
@@ -16,6 +16,11 @@ def as_dict(pds):
 def backfill_pagerdutyservices(apps, schema_editor):
     PagerDutyService = apps.get_model("sentry", "PagerDutyService")
     OrganizationIntegration = apps.get_model("sentry", "OrganizationIntegration")
+    try:
+        PagerDutyService.objects.first()
+    except ProgrammingError:
+        # Table was not created as the pagerdutyservice model has been removed.
+        return
 
     for pds in RangeQuerySetWrapper(PagerDutyService.objects.all()):
         try:
@@ -55,6 +60,6 @@ class Migration(CheckedMigration):
         migrations.RunPython(
             backfill_pagerdutyservices,
             reverse_code=migrations.RunPython.noop,
-            hints={"tables": ["sentry_pagerdutyservice", "sentry_organizationintegration"]},
+            hints={"tables": ["sentry_organizationintegration"]},
         ),
     ]