Skip to content

Commit 80bbd3e

Browse files
cathtengJesse-Box
authored andcommitted
chore(aci): make DetectorGroup unique on Group (#102928)
1 parent f8c9f4b commit 80bbd3e

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ tempest: 0001_squashed_0002_make_message_type_nullable
3939

4040
uptime: 0048_delete_uptime_status_columns
4141

42-
workflow_engine: 0094_backfill_issue_stream_detector_workflows
42+
workflow_engine: 0095_unique_detectorgroup_group
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Generated by Django 5.2.1 on 2025-11-06 22:43
2+
3+
import django.db.models.deletion
4+
from django.db import migrations
5+
6+
import sentry.db.models.fields.foreignkey
7+
from sentry.new_migrations.migrations import CheckedMigration
8+
9+
10+
class Migration(CheckedMigration):
11+
# This flag is used to mark that a migration shouldn't be automatically run in production.
12+
# This should only be used for operations where it's safe to run the migration after your
13+
# code has deployed. So this should not be used for most operations that alter the schema
14+
# of a table.
15+
# Here are some things that make sense to mark as post deployment:
16+
# - Large data migrations. Typically we want these to be run manually so that they can be
17+
# monitored and not block the deploy for a long period of time while they run.
18+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
19+
# run this outside deployments so that we don't block them. Note that while adding an index
20+
# is a schema change, it's completely safe to run the operation after the code has deployed.
21+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
22+
23+
is_post_deployment = True
24+
25+
dependencies = [
26+
("sentry", "1003_group_history_prev_history_safe_removal"),
27+
("workflow_engine", "0094_backfill_issue_stream_detector_workflows"),
28+
]
29+
30+
operations = [
31+
migrations.AlterField(
32+
model_name="detectorgroup",
33+
name="group",
34+
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
35+
on_delete=django.db.models.deletion.CASCADE, to="sentry.group", unique=True
36+
),
37+
),
38+
migrations.AlterUniqueTogether(
39+
name="detectorgroup",
40+
unique_together=set(),
41+
),
42+
]

src/sentry/workflow_engine/models/detector_group.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ class DetectorGroup(DefaultFieldsModel):
1313
__relocation_scope__ = RelocationScope.Excluded
1414

1515
detector = FlexibleForeignKey("workflow_engine.Detector", on_delete=models.CASCADE)
16-
group = FlexibleForeignKey("sentry.Group", on_delete=models.CASCADE)
16+
group = FlexibleForeignKey("sentry.Group", on_delete=models.CASCADE, unique=True)
1717

1818
class Meta:
1919
db_table = "workflow_engine_detectorgroup"
2020
app_label = "workflow_engine"
21-
unique_together = (("detector", "group"),)
2221
indexes = [
2322
models.Index(fields=["detector", "-date_added"], name="detectorgroup_det_date_idx"),
2423
]

0 commit comments

Comments
 (0)