Browse Source

feat(issue-priority): Add priority column to group table (#63351)

Adds a priority column to the group table. The column supports null
values right now, but can be made non-nullable once we've migrated all
groups to have a priority.
Snigdha Sharma 1 year ago
parent
commit
54a4342ea7

+ 1 - 1
migrations_lockfile.txt

@@ -9,5 +9,5 @@ feedback: 0003_feedback_add_env
 hybridcloud: 0009_make_user_id_optional_for_slug_reservation_replica
 nodestore: 0002_nodestore_no_dictfield
 replays: 0003_add_size_to_recording_segment
-sentry: 0630_better_monitor_latest_index
+sentry: 0631_add_priority_columns_to_groupedmessage
 social_auth: 0002_default_auto_field

+ 53 - 0
src/sentry/migrations/0631_add_priority_columns_to_groupedmessage.py

@@ -0,0 +1,53 @@
+# Generated by Django 3.2.23 on 2024-01-16 22:46
+
+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
+
+    dependencies = [
+        ("sentry", "0630_better_monitor_latest_index"),
+    ]
+
+    operations = [
+        migrations.SeparateDatabaseAndState(
+            database_operations=[
+                migrations.RunSQL(
+                    """
+                    ALTER TABLE "sentry_groupedmessage" ADD COLUMN "priority" int NULL;
+                    ALTER TABLE "sentry_groupedmessage" ADD COLUMN "priority_locked" bool NOT NULL default false;
+                    """,
+                    reverse_sql="""
+                    ALTER TABLE "sentry_groupedmessage" DROP COLUMN "priority";
+                    ALTER TABLE "sentry_groupedmessage" DROP COLUMN "priority_locked";
+                    """,
+                    hints={"tables": ["sentry_groupedmessage"]},
+                ),
+            ],
+            state_operations=[
+                migrations.AlterField(
+                    model_name="group",
+                    name="priority",
+                    field=models.PositiveSmallIntegerField(null=True),
+                ),
+                migrations.AlterField(
+                    model_name="group",
+                    name="priority_locked",
+                    field=models.BooleanField(default=False),
+                ),
+            ],
+        )
+    ]

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

@@ -543,6 +543,8 @@ class Group(Model):
     data: models.Field[dict[str, Any], dict[str, Any]] = GzippedDictField(blank=True, null=True)
     short_id = BoundedBigIntegerField(null=True)
     type = BoundedPositiveIntegerField(default=ErrorGroupType.type_id, db_index=True)
+    priority = models.PositiveSmallIntegerField(null=True)
+    priority_locked = models.BooleanField(default=False)
 
     objects: ClassVar[GroupManager] = GroupManager(cache_fields=("id",))
 

+ 14 - 0
tests/sentry/migrations/test_0631_add_priority_column_to_groupedmessage.py

@@ -0,0 +1,14 @@
+from sentry.testutils.cases import TestMigrations
+
+
+class AddPriorityColumnTests(TestMigrations):
+    migrate_from = "0630_better_monitor_latest_index"
+    migrate_to = "0631_add_priority_columns_to_groupedmessage"
+
+    def setup_initial_state(self):
+        self.group = self.create_group()
+
+    def test(self):
+        self.group.refresh_from_db()
+        assert self.group.priority is None
+        assert not self.group.priority_locked