Skip to content

Commit 0245003

Browse files
authored
feat(aci): Re-add table to look up groups created by detectors (#95243)
redo of #94972 This table will be used to look up groups that were created by a detector to display on the monitors page in the UI.
1 parent 9641728 commit 0245003

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

migrations_lockfile.txt

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

3636
uptime: 0001_squashed_0042_extra_uptime_indexes
3737

38-
workflow_engine: 0075_add_index_to_dcg_action
38+
workflow_engine: 0076_add_detector_group_table
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Generated by Django 5.2.1 on 2025-07-09 17:43
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
import sentry.db.models.fields.bounded
7+
import sentry.db.models.fields.foreignkey
8+
from sentry.new_migrations.migrations import CheckedMigration
9+
from sentry.new_migrations.monkey.special import SafeRunSQL
10+
11+
12+
class Migration(CheckedMigration):
13+
# This flag is used to mark that a migration shouldn't be automatically run in production.
14+
# This should only be used for operations where it's safe to run the migration after your
15+
# code has deployed. So this should not be used for most operations that alter the schema
16+
# of a table.
17+
# Here are some things that make sense to mark as post deployment:
18+
# - Large data migrations. Typically we want these to be run manually so that they can be
19+
# monitored and not block the deploy for a long period of time while they run.
20+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
21+
# run this outside deployments so that we don't block them. Note that while adding an index
22+
# is a schema change, it's completely safe to run the operation after the code has deployed.
23+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
24+
25+
is_post_deployment = False
26+
27+
dependencies = [
28+
("sentry", "0943_create_data_access_grant"),
29+
("workflow_engine", "0075_add_index_to_dcg_action"),
30+
]
31+
32+
operations = [
33+
SafeRunSQL(
34+
"""DROP TABLE IF EXISTS "workflow_engine_detectorgroup";""",
35+
reverse_sql=migrations.RunSQL.noop,
36+
hints={"tables": ["workflow_engine_detectorgroup"]},
37+
), # this migration was successfully run in S4S and DE, failed in US
38+
migrations.CreateModel(
39+
name="DetectorGroup",
40+
fields=[
41+
(
42+
"id",
43+
sentry.db.models.fields.bounded.BoundedBigAutoField(
44+
primary_key=True, serialize=False
45+
),
46+
),
47+
("date_updated", models.DateTimeField(auto_now=True)),
48+
("date_added", models.DateTimeField(auto_now_add=True)),
49+
(
50+
"detector",
51+
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
52+
on_delete=django.db.models.deletion.CASCADE,
53+
to="workflow_engine.detector",
54+
),
55+
),
56+
(
57+
"group",
58+
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
59+
db_constraint=False,
60+
on_delete=django.db.models.deletion.CASCADE,
61+
to="sentry.group",
62+
),
63+
),
64+
],
65+
options={
66+
"db_table": "workflow_engine_detectorgroup",
67+
},
68+
),
69+
]

src/sentry/workflow_engine/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"DataSource",
1313
"DataSourceDetector",
1414
"Detector",
15+
"DetectorGroup",
1516
"DetectorState",
1617
"DetectorWorkflow",
1718
"IncidentGroupOpenPeriod",
@@ -32,6 +33,7 @@
3233
from .data_source_detector import DataSourceDetector
3334
from .datacondition_alertruletrigger import DataConditionAlertRuleTrigger
3435
from .detector import Detector
36+
from .detector_group import DetectorGroup
3537
from .detector_state import DetectorState
3638
from .detector_workflow import DetectorWorkflow
3739
from .incident_groupopenperiod import IncidentGroupOpenPeriod
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django.db import models
2+
3+
from sentry.backup.scopes import RelocationScope
4+
from sentry.db.models import DefaultFieldsModel, FlexibleForeignKey, region_silo_model
5+
6+
7+
@region_silo_model
8+
class DetectorGroup(DefaultFieldsModel):
9+
"""
10+
A model to represent the relationship between a detector and a group.
11+
"""
12+
13+
__relocation_scope__ = RelocationScope.Excluded
14+
15+
detector = FlexibleForeignKey("workflow_engine.Detector", on_delete=models.CASCADE)
16+
group = FlexibleForeignKey("sentry.Group", on_delete=models.CASCADE, db_constraint=False)
17+
18+
class Meta:
19+
db_table = "workflow_engine_detectorgroup"
20+
app_label = "workflow_engine"

0 commit comments

Comments
 (0)