Skip to content

Commit 2d489b9

Browse files
feat(migrations): Add new index to IncidentTrigger model (#58467)
This PR adds a new index to `IncidentTrigger` to make querying for the metric alert rate limiting feature more efficient #58032. [Query in question](https://github.com/getsentry/sentry/pull/58032/files#diff-d262481ba0aaae3473d14f62d3cbb554e099bda1093454b7935890139f3fe5a8R558-R563)
1 parent f421fee commit 2d489b9

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ feedback: 0003_feedback_add_env
99
hybridcloud: 0005_add_missing_org_integration_scope
1010
nodestore: 0002_nodestore_no_dictfield
1111
replays: 0003_add_size_to_recording_segment
12-
sentry: 0578_add_query_and_users_to_custom_dynamic_sampling_rules
12+
sentry: 0579_index_incident_trigger
1313
social_auth: 0002_default_auto_field

src/sentry/incidents/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ class Meta:
523523
app_label = "sentry"
524524
db_table = "sentry_incidenttrigger"
525525
unique_together = (("incident", "alert_rule_trigger"),)
526+
index_together = (("alert_rule_trigger", "incident_id"),)
526527

527528

528529
class AlertRuleTriggerManager(BaseManager):
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 3.2.20 on 2023-10-20 15:31
2+
3+
from django.db import migrations
4+
5+
from sentry.new_migrations.migrations import CheckedMigration
6+
7+
8+
class Migration(CheckedMigration):
9+
# This flag is used to mark that a migration shouldn't be automatically run in production. For
10+
# the most part, this should only be used for operations where it's safe to run the migration
11+
# after your code has deployed. So this should not be used for most operations that alter the
12+
# schema of a table.
13+
# Here are some things that make sense to mark as dangerous:
14+
# - Large data migrations. Typically we want these to be run manually by ops so that they can
15+
# be monitored and not block the deploy for a long period of time while they run.
16+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
17+
# have ops run this and not block the deploy. Note that while adding an index is a schema
18+
# change, it's completely safe to run the operation after the code has deployed.
19+
is_dangerous = True
20+
21+
dependencies = [
22+
("sentry", "0578_add_query_and_users_to_custom_dynamic_sampling_rules"),
23+
]
24+
25+
operations = [
26+
migrations.AlterIndexTogether(
27+
name="incidenttrigger",
28+
index_together={("alert_rule_trigger", "incident_id")},
29+
),
30+
]

0 commit comments

Comments
 (0)