Browse Source

feat(migration): Add suspect_committer_auto_assignment column (#39382)

## Objective:
Adds the new setting to auto assign Issues to the Suspect Committer.
NisanthanNanthakumar 2 years ago
parent
commit
a6ef608a3c

+ 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: 0320_rule_history_event_id
+sentry: 0321_suspect_committer_auto_assignment
 social_auth: 0001_initial

+ 51 - 0
src/sentry/migrations/0321_suspect_committer_auto_assignment.py

@@ -0,0 +1,51 @@
+# Generated by Django 2.2.28 on 2022-09-27 23:29
+
+from django.db import migrations, models
+
+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
+
+    # This flag is used to decide whether to run this migration in a transaction or not. Generally
+    # we don't want to run in a transaction here, since for long running operations like data
+    # back-fills this results in us locking an increasing number of rows until we finally commit.
+    atomic = False
+
+    dependencies = [
+        ("sentry", "0320_rule_history_event_id"),
+    ]
+
+    operations = [
+        migrations.SeparateDatabaseAndState(
+            database_operations=[
+                migrations.RunSQL(
+                    """
+                    ALTER TABLE "sentry_projectownership" ADD COLUMN "suspect_committer_auto_assignment" BOOLEAN NOT NULL DEFAULT false;
+                    """,
+                    reverse_sql="""
+                    ALTER TABLE "sentry_projectownership" DROP COLUMN "suspect_committer_auto_assignment";
+                    """,
+                    hints={"tables": ["sentry_projectownership"]},
+                ),
+            ],
+            state_operations=[
+                migrations.AddField(
+                    model_name="projectownership",
+                    name="suspect_committer_auto_assignment",
+                    field=models.BooleanField(default=False),
+                ),
+            ],
+        )
+    ]

+ 2 - 0
src/sentry/models/projectownership.py

@@ -22,11 +22,13 @@ class ProjectOwnership(Model):
     raw = models.TextField(null=True)
     schema = JSONField(null=True)
     fallthrough = models.BooleanField(default=False)
+    # Auto Assignment through Ownership Rules & Code Owners
     auto_assignment = models.BooleanField(default=False)
     date_created = models.DateTimeField(default=timezone.now)
     last_updated = models.DateTimeField(default=timezone.now)
     is_active = models.BooleanField(default=True)
     codeowners_auto_sync = models.BooleanField(default=True, null=True)
+    suspect_committer_auto_assignment = models.BooleanField(default=False)
 
     # An object to indicate ownership is implicitly everyone
     Everyone = object()