Browse Source

ref(migration): Make repositoryprojectpathconfig organization_integration foreignkey nullable (#23673)

Objective:
We need to create a migration to make organization_integration_id nullable. This allows Code Path Mappings to be an integration-agnostic feature.
NisanthanNanthakumar 4 years ago
parent
commit
9f2b060c27

+ 1 - 1
migrations_lockfile.txt

@@ -10,7 +10,7 @@ auth: 0008_alter_user_username_max_length
 contenttypes: 0002_remove_content_type_name
 jira_ac: 0001_initial
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0156_add_mark_reviewed_activity
+sentry: 0157_make_repositoryprojectpathconfig_organization_integration_nullable
 sessions: 0001_initial
 sites: 0002_alter_domain_unique
 social_auth: 0001_initial

+ 43 - 0
src/sentry/migrations/0157_make_repositoryprojectpathconfig_organization_integration_nullable.py

@@ -0,0 +1,43 @@
+# Generated by Django 1.11.29 on 2021-02-05 23:58
+
+from django.db import migrations
+import django.db.models.deletion
+import sentry.db.models.fields.foreignkey
+
+
+class Migration(migrations.Migration):
+    # This flag is used to mark that a migration shouldn't be automatically run in
+    # production. We set this to True for operations that we think are risky and want
+    # someone from ops to run manually and monitor.
+    # General advice is that if in doubt, mark your migration as `is_dangerous`.
+    # Some things you should always mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that
+    #   they can be monitored. Since data migrations will now hold a transaction open
+    #   this is even more important.
+    # - Adding columns to highly active tables, even ones that are NULL.
+    is_dangerous = False
+
+    # This flag is used to decide whether to run this migration in a transaction or not.
+    # By default we prefer to run in a transaction, but for migrations where you want
+    # to `CREATE INDEX CONCURRENTLY` this needs to be set to False. Typically you'll
+    # want to create an index concurrently when adding one to an existing table.
+    # You'll also usually want to set this to `False` if you're writing a data
+    # migration, since we don't want the entire migration to run in one long-running
+    # transaction.
+    atomic = True
+
+    dependencies = [
+        ("sentry", "0156_add_mark_reviewed_activity"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="repositoryprojectpathconfig",
+            name="organization_integration",
+            field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                null=True,
+                on_delete=django.db.models.deletion.CASCADE,
+                to="sentry.OrganizationIntegration",
+            ),
+        ),
+    ]

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

@@ -51,7 +51,7 @@ class RepositoryProjectPathConfig(DefaultFieldsModel):
 
     repository = FlexibleForeignKey("sentry.Repository")
     project = FlexibleForeignKey("sentry.Project", db_constraint=False)
-    organization_integration = FlexibleForeignKey("sentry.OrganizationIntegration")
+    organization_integration = FlexibleForeignKey("sentry.OrganizationIntegration", null=True)
     stack_root = models.TextField()
     source_root = models.TextField()
     default_branch = models.TextField(null=True)