Browse Source

feat(migration): add index on Group.type (#45543)

Needed primarily for this
[PR](https://github.com/getsentry/sentry/pull/44645). We already have a
multi-column index that includes `type` here:
https://github.com/getsentry/sentry/blob/a93e191a3e87b3e551afe361b5bda6f6bc9c8a91/src/sentry/migrations/0317_groupedmessage_type_index.py#L47
to support issue search on postgres. So this additional index could
maybe be removed later.
Gilbert Szeto 2 years ago
parent
commit
c3ada47528

+ 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: 0376_longer_option_names
+sentry: 0377_groupedmesssage_type_individual_index
 social_auth: 0001_initial

+ 34 - 0
src/sentry/migrations/0377_groupedmesssage_type_individual_index.py

@@ -0,0 +1,34 @@
+# Generated by Django 2.2.28 on 2023-03-08 22:04
+
+from django.db import migrations
+
+import sentry.db.models.fields.bounded
+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 = True
+
+    dependencies = [
+        ("sentry", "0376_longer_option_names"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="group",
+            name="type",
+            field=sentry.db.models.fields.bounded.BoundedPositiveIntegerField(
+                db_index=True, default=1
+            ),
+        ),
+    ]

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

@@ -421,7 +421,7 @@ class Group(Model):
     is_public = models.NullBooleanField(default=False, null=True)
     data = GzippedDictField(blank=True, null=True)
     short_id = BoundedBigIntegerField(null=True)
-    type = BoundedPositiveIntegerField(default=ErrorGroupType.type_id)
+    type = BoundedPositiveIntegerField(default=ErrorGroupType.type_id, db_index=True)
 
     objects = GroupManager(cache_fields=("id",))