Skip to content

Commit 5e9f8cb

Browse files
ref: represent missing workflow_engine indexes in code (#91882)
these are already present in production but due to the way the fields were changed left behind the state of the indexes that are present <!-- Describe your PR here. -->
1 parent 16fd5c7 commit 5e9f8cb

File tree

5 files changed

+71
-6
lines changed

5 files changed

+71
-6
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ tempest: 0002_make_message_type_nullable
2929

3030
uptime: 0042_extra_uptime_indexes
3131

32-
workflow_engine: 0061_backfill_metric_alert_resolution_action_filters
32+
workflow_engine: 0062_workflow_engine_missing_indexes
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Generated by Django 5.2.1 on 2025-05-19 17:39
2+
from django.db import migrations
3+
4+
import sentry.db.models.fields.bounded
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.
10+
# This should only be used for operations where it's safe to run the migration after your
11+
# code has deployed. So this should not be used for most operations that alter the schema
12+
# of a table.
13+
# Here are some things that make sense to mark as post deployment:
14+
# - Large data migrations. Typically we want these to be run manually so that they can be
15+
# 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+
# run this outside deployments so that we don't block them. Note that while adding an index
18+
# is a schema change, it's completely safe to run the operation after the code has deployed.
19+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
20+
21+
is_post_deployment = False
22+
23+
dependencies = [
24+
("workflow_engine", "0061_backfill_metric_alert_resolution_action_filters"),
25+
]
26+
27+
operations = [
28+
migrations.SeparateDatabaseAndState(
29+
state_operations=[
30+
migrations.AlterField(
31+
model_name="actionalertruletriggeraction",
32+
name="alert_rule_trigger_action_id",
33+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
34+
),
35+
migrations.AlterField(
36+
model_name="alertruledetector",
37+
name="alert_rule_id",
38+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
39+
db_index=True, null=True
40+
),
41+
),
42+
migrations.AlterField(
43+
model_name="alertruledetector",
44+
name="rule_id",
45+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
46+
db_index=True, null=True
47+
),
48+
),
49+
migrations.AlterField(
50+
model_name="alertruleworkflow",
51+
name="alert_rule_id",
52+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
53+
db_index=True, null=True
54+
),
55+
),
56+
migrations.AlterField(
57+
model_name="alertruleworkflow",
58+
name="rule_id",
59+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
60+
db_index=True, null=True
61+
),
62+
),
63+
]
64+
)
65+
]

src/sentry/workflow_engine/models/action_alertruletriggeraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ class ActionAlertRuleTriggerAction(DefaultFieldsModel):
1515

1616
__relocation_scope__ = RelocationScope.Excluded
1717

18-
alert_rule_trigger_action_id = BoundedBigIntegerField()
18+
alert_rule_trigger_action_id = BoundedBigIntegerField(db_index=True)
1919
action = FlexibleForeignKey("workflow_engine.Action")

src/sentry/workflow_engine/models/alertrule_detector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class AlertRuleDetector(DefaultFieldsModel):
1717

1818
__relocation_scope__ = RelocationScope.Organization
1919

20-
alert_rule_id = BoundedBigIntegerField(null=True)
21-
rule_id = BoundedBigIntegerField(null=True)
20+
alert_rule_id = BoundedBigIntegerField(null=True, db_index=True)
21+
rule_id = BoundedBigIntegerField(null=True, db_index=True)
2222
detector = FlexibleForeignKey("workflow_engine.Detector")
2323

2424
class Meta:

src/sentry/workflow_engine/models/alertrule_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class AlertRuleWorkflow(DefaultFieldsModel):
1818

1919
__relocation_scope__ = RelocationScope.Organization
2020

21-
alert_rule_id = BoundedBigIntegerField(null=True)
22-
rule_id = BoundedBigIntegerField(null=True)
21+
alert_rule_id = BoundedBigIntegerField(null=True, db_index=True)
22+
rule_id = BoundedBigIntegerField(null=True, db_index=True)
2323
workflow = FlexibleForeignKey("workflow_engine.Workflow")
2424

2525
class Meta:

0 commit comments

Comments
 (0)