Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c6a52de
remove the 'required' field from an action, this is a legacy field.
saponifi3d Nov 13, 2024
f5938f1
Remove the temp project_id field and make an association with the pro…
saponifi3d Nov 13, 2024
6145662
Add the ownermodel to the workflow, add 'enabled' flag for snooze
saponifi3d Nov 13, 2024
9025e7c
Update the detector model:
saponifi3d Nov 13, 2024
c61e0ca
add environment_id, created_by, frequency, and snoozed fields to Work…
cathteng Nov 13, 2024
2beeebb
remove snooze, we have 'enabled'
cathteng Nov 13, 2024
f9efc83
use SET_NULL for HybridCloudForeignKey cascade
cathteng Nov 13, 2024
a2b2d00
re-add the organization, it broke a bunch of stuff without it. If a p…
saponifi3d Nov 14, 2024
58b2567
Update detector model
saponifi3d Nov 15, 2024
abba861
make this a bounded integer field so it will be droppable correctly
saponifi3d Nov 15, 2024
73c0cda
remove org from test utils
saponifi3d Nov 15, 2024
d897914
make required nullable for the first phase of the migration
saponifi3d Nov 15, 2024
14306a0
only make it nullable
saponifi3d Nov 15, 2024
1dea1d3
update snapshots
saponifi3d Nov 15, 2024
09fdacf
add comment to remove field
saponifi3d Nov 15, 2024
82d812e
change how the factories / fixtures work to fix tests
saponifi3d Nov 15, 2024
cbb8d09
Change relocation scope back to organization, that's used for the pro…
saponifi3d Nov 15, 2024
25f2ab1
updatee the dependenices after changing the relocation scope
saponifi3d Nov 15, 2024
6a345e8
create an association with the project rather than using a hardcoded 1
saponifi3d Nov 16, 2024
b334df0
seems okay, but need to figure out the rest of the details in the jso…
saponifi3d Nov 19, 2024
1e13d61
Update workflow / detector models, and change to have json_config exp…
saponifi3d Nov 19, 2024
52acf94
Update json field to be dict by default
saponifi3d Nov 19, 2024
343a7c7
Add an error to the base models -- helps with typing errors and will …
saponifi3d Nov 19, 2024
d071c24
Remove the test for the mixin cause it seems like it's problematic. j…
saponifi3d Nov 21, 2024
eef52e4
PR Feedback
saponifi3d Nov 21, 2024
24e9f9b
GENERATED - SQL Migration
saponifi3d Nov 21, 2024
1bca30a
GENERATED - Update Model Dependencies
saponifi3d Nov 21, 2024
f9fc70c
GENERATED - Update snapshots
saponifi3d Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions fixtures/backup/model_dependencies/detailed.json
Original file line number Diff line number Diff line change
Expand Up @@ -6505,12 +6505,17 @@
]
},
"workflow_engine.detector": {
"dangling": false,
"dangling": true,
"foreign_keys": {
"created_by_id": {
"kind": "HybridCloudForeignKey",
"model": "sentry.user",
"nullable": true
},
"organization": {
"kind": "FlexibleForeignKey",
"model": "sentry.organization",
"nullable": false
"nullable": true
},
"owner_team": {
"kind": "FlexibleForeignKey",
Expand All @@ -6522,6 +6527,11 @@
"model": "sentry.user",
"nullable": true
},
"project": {
"kind": "FlexibleForeignKey",
"model": "sentry.project",
"nullable": true
},
"workflow_condition_group": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.dataconditiongroup",
Expand Down Expand Up @@ -6591,11 +6601,31 @@
"workflow_engine.workflow": {
"dangling": false,
"foreign_keys": {
"created_by_id": {
"kind": "HybridCloudForeignKey",
"model": "sentry.user",
"nullable": true
},
"environment": {
"kind": "FlexibleForeignKey",
"model": "sentry.environment",
"nullable": true
},
"organization": {
"kind": "FlexibleForeignKey",
"model": "sentry.organization",
"nullable": false
},
"owner_team": {
"kind": "FlexibleForeignKey",
"model": "sentry.team",
"nullable": true
},
"owner_user_id": {
"kind": "HybridCloudForeignKey",
"model": "sentry.user",
"nullable": true
},
"when_condition_group": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.dataconditiongroup",
Expand Down
4 changes: 4 additions & 0 deletions fixtures/backup/model_dependencies/flat.json
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@
],
"workflow_engine.detector": [
"sentry.organization",
"sentry.project",
"sentry.team",
"sentry.user",
"workflow_engine.dataconditiongroup"
Expand All @@ -911,7 +912,10 @@
"workflow_engine.workflow"
],
"workflow_engine.workflow": [
"sentry.environment",
"sentry.organization",
"sentry.team",
"sentry.user",
"workflow_engine.dataconditiongroup"
],
"workflow_engine.workflowdataconditiongroup": [
Expand Down
12 changes: 6 additions & 6 deletions fixtures/backup/model_dependencies/sorted.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@
"workflow_engine.dataconditiongroup",
"workflow_engine.dataconditiongroupaction",
"workflow_engine.datasource",
"workflow_engine.detector",
"workflow_engine.detectorstate",
"workflow_engine.workflow",
"workflow_engine.workflowdataconditiongroup",
"workflow_engine.detectorworkflow",
"workflow_engine.datasourcedetector",
"workflow_engine.datacondition",
"sentry.savedsearch",
"sentry.rollbackuser",
Expand Down Expand Up @@ -119,6 +113,9 @@
"flags.flagwebhooksigningsecretmodel",
"flags.flagauditlogmodel",
"feedback.feedback",
"workflow_engine.workflow",
"workflow_engine.detector",
"workflow_engine.datasourcedetector",
"uptime.projectuptimesubscription",
"sentry.userreport",
"sentry.useroption",
Expand Down Expand Up @@ -205,6 +202,9 @@
"sentry.apiauthorization",
"sentry.alertrule",
"hybridcloud.apitokenreplica",
"workflow_engine.workflowdataconditiongroup",
"workflow_engine.detectorworkflow",
"workflow_engine.detectorstate",
"sentry.teamkeytransaction",
"sentry.snubaqueryeventtype",
"sentry.sentryappinstallation",
Expand Down
12 changes: 6 additions & 6 deletions fixtures/backup/model_dependencies/truncate.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@
"workflow_engine_dataconditiongroup",
"workflow_engine_dataconditiongroupaction",
"workflow_engine_datasource",
"workflow_engine_detector",
"workflow_engine_detectorstate",
"workflow_engine_workflow",
"workflow_engine_workflowdataconditiongroup",
"workflow_engine_detectorworkflow",
"workflow_engine_datasourcedetector",
"workflow_engine_datacondition",
"sentry_savedsearch",
"sentry_rollbackuser",
Expand Down Expand Up @@ -119,6 +113,9 @@
"flags_webhooksigningsecret",
"flags_audit_log",
"feedback_feedback",
"workflow_engine_workflow",
"workflow_engine_detector",
"workflow_engine_datasourcedetector",
"uptime_projectuptimesubscription",
"sentry_userreport",
"sentry_useroption",
Expand Down Expand Up @@ -205,6 +202,9 @@
"sentry_apiauthorization",
"sentry_alertrule",
"hybridcloud_apitokenreplica",
"workflow_engine_workflowdataconditiongroup",
"workflow_engine_detectorworkflow",
"workflow_engine_detectorstate",
"sentry_performanceteamkeytransaction",
"sentry_snubaqueryeventtype",
"sentry_sentryappinstallation",
Expand Down
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ replays: 0004_index_together
sentry: 0792_add_unique_index_apiauthorization
social_auth: 0002_default_auto_field
uptime: 0018_add_trace_sampling_field_to_uptime
workflow_engine: 0013_related_name_conditions_on_dcg
workflow_engine: 0014_model_additions_for_milestones
9 changes: 1 addition & 8 deletions src/sentry/testutils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2126,21 +2126,14 @@ def create_data_source(
@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_detector(
organization: Organization | None = None,
name: str | None = None,
owner_user_id: int | None = None,
owner_team: Team | None = None,
**kwargs,
) -> Detector:
if organization is None:
organization = Factories.create_organization()
if name is None:
name = petname.generate(2, " ", letters=10).title()

return Detector.objects.create(
organization=organization,
name=name,
owner_user_id=owner_user_id,
owner_team=owner_team,
**kwargs,
)

Expand Down
12 changes: 10 additions & 2 deletions src/sentry/testutils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,16 @@ def create_data_condition(
condition_group=condition_group,
)

def create_detector(self, *args, **kwargs) -> Detector:
return Factories.create_detector(*args, **kwargs)
def create_detector(
self,
*args,
project=None,
**kwargs,
) -> Detector:
if project is None:
project = self.create_project(organization=self.organization)

return Factories.create_detector(*args, project=project, **kwargs)

def create_detector_state(self, *args, **kwargs) -> DetectorState:
return Factories.create_detector_state(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/testutils/helpers/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def create_exhaustive_organization(

# Setup a test 'Issue Rule' and 'Automation'
workflow = self.create_workflow(organization=org)
detector = self.create_detector(organization=org)
detector = self.create_detector(project=project)
self.create_detector_workflow(detector=detector, workflow=workflow)
self.create_detector_state(detector=detector)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Generated by Django 5.1.1 on 2024-11-21 21:05

import django.db.models.deletion
from django.db import migrations, models

import sentry.db.models.fields.foreignkey
import sentry.db.models.fields.hybrid_cloud_foreign_key
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.
# 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 post deployment:
# - Large data migrations. Typically we want these to be run manually 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
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("sentry", "0792_add_unique_index_apiauthorization"),
("workflow_engine", "0013_related_name_conditions_on_dcg"),
]

operations = [
migrations.AddField(
model_name="detector",
name="config",
field=models.JSONField(db_default={}),
),
migrations.AddField(
model_name="detector",
name="created_by_id",
field=sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey(
"sentry.User", db_index=True, null=True, on_delete="SET_NULL"
),
),
migrations.AddField(
model_name="detector",
name="description",
field=models.TextField(null=True),
),
migrations.AddField(
model_name="detector",
name="enabled",
field=models.BooleanField(db_default=True),
),
migrations.AddField(
model_name="detector",
name="project",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="sentry.project"
),
),
migrations.AddField(
model_name="workflow",
name="config",
field=models.JSONField(db_default={}),
),
migrations.AddField(
model_name="workflow",
name="created_by_id",
field=sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey(
"sentry.User", db_index=True, null=True, on_delete="SET_NULL"
),
),
migrations.AddField(
model_name="workflow",
name="enabled",
field=models.BooleanField(db_default=True),
),
migrations.AddField(
model_name="workflow",
name="environment",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="sentry.environment"
),
),
migrations.AddField(
model_name="workflow",
name="owner_team",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
null=True, on_delete=django.db.models.deletion.SET_NULL, to="sentry.team"
),
),
migrations.AddField(
model_name="workflow",
name="owner_user_id",
field=sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey(
"sentry.User", db_index=True, null=True, on_delete="SET_NULL"
),
),
migrations.AlterField(
model_name="action",
name="required",
field=models.BooleanField(default=False, null=True),
),
migrations.AlterField(
model_name="detector",
name="organization",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="sentry.organization"
),
),
migrations.AlterField(
model_name="workflow",
name="when_condition_group",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="workflow_engine.dataconditiongroup",
),
),
]
10 changes: 3 additions & 7 deletions src/sentry/workflow_engine/models/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ class Type(models.TextChoices):
Notification = "SendNotificationAction"
TriggerWorkflow = "TriggerWorkflowAction"

"""
Required actions cannot be disabled by the user, and will not be displayed in the UI.
These actions will be used internally, to trigger other aspects of the system.
For example, creating a new issue in the Issue Platform or a detector emitting an event.
"""
required = models.BooleanField(default=False)

# The type field is used to denote the type of action we want to trigger
type = models.TextField(choices=Type.choices)
data = models.JSONField(default=dict)

# TODO - finish removing this field
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JFYI: I've got an operation coming soon that will make deleting these things simpler #81098

required = models.BooleanField(default=False, null=True)

# LEGACY: The integration_id is used to map the integration_id found in the AlertRuleTriggerAction
# This allows us to map the way we're saving the notification channels to the action.
integration_id = HybridCloudForeignKey(
Expand Down
Loading
Loading