Browse Source

Activation condition singular rename (#68070)

migration to make `activation condition` singular
Nathan Hsieh 11 months ago
parent
commit
606b10293d

+ 1 - 1
migrations_lockfile.txt

@@ -9,5 +9,5 @@ feedback: 0004_index_together
 hybridcloud: 0015_apitokenreplica_hashed_token_index
 nodestore: 0002_nodestore_no_dictfield
 replays: 0004_index_together
-sentry: 0684_monitor_check_in_config_nullable
+sentry: 0685_alert_rule_conditons_rename_singular
 social_auth: 0002_default_auto_field

+ 2 - 1
src/sentry/incidents/models/alert_rule.py

@@ -159,7 +159,8 @@ class AlertRuleManager(BaseManager["AlertRule"]):
             )
             created_subscriptions = []
             for alert_rule in project_alert_rules:
-                if alert_rule.activation_conditions.filter(
+                # an alert rule should only ever have a single condition
+                if alert_rule.activation_condition.filter(
                     condition_type=activation_condition.value
                 ).exists():
                     # if an activated alert rule exists with the passed condition

+ 1 - 1
src/sentry/incidents/models/alert_rule_activations.py

@@ -29,7 +29,7 @@ class AlertRuleActivationCondition(Model):
 
     __relocation_scope__ = RelocationScope.Organization
 
-    alert_rule = FlexibleForeignKey("sentry.AlertRule", related_name="activation_conditions")
+    alert_rule = FlexibleForeignKey("sentry.AlertRule", related_name="activation_condition")
     label = models.TextField()
     condition_type = models.SmallIntegerField(null=True)
 

+ 37 - 0
src/sentry/migrations/0685_alert_rule_conditons_rename_singular.py

@@ -0,0 +1,37 @@
+# Generated by Django 5.0.3 on 2024-04-01 23:41
+
+import django.db.models.deletion
+from django.db import migrations
+
+import sentry.db.models.fields.foreignkey
+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. For
+    # the most part, 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 dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops 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
+    #   have ops run this and not block the deploy. Note that while adding an index is a schema
+    #   change, it's completely safe to run the operation after the code has deployed.
+    is_dangerous = False
+
+    dependencies = [
+        ("sentry", "0684_monitor_check_in_config_nullable"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="alertruleactivationcondition",
+            name="alert_rule",
+            field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                on_delete=django.db.models.deletion.CASCADE,
+                related_name="activation_condition",
+                to="sentry.alertrule",
+            ),
+        ),
+    ]