Browse Source

feat(integration): add status column for deletion (#65733)

Add status column in Alert Rule Trigger Action so that we can schedule
deletions and filter out those rows. This is a prerequisite for
https://github.com/getsentry/sentry/pull/65369
Yash Kamothi 1 year ago
parent
commit
71c2b3b883

+ 1 - 1
migrations_lockfile.txt

@@ -9,5 +9,5 @@ feedback: 0004_index_together
 hybridcloud: 0012_apitoken_increase_token_length
 nodestore: 0002_nodestore_no_dictfield
 replays: 0004_index_together
-sentry: 0656_add_discover_dataset_split_dashboard
+sentry: 0657_add_status_column_for_alert_rule_trigger_action
 social_auth: 0002_default_auto_field

+ 5 - 0
src/sentry/incidents/models.py

@@ -14,8 +14,10 @@ from django.utils import timezone
 from sentry.backup.dependencies import PrimaryKeyMap, get_model_name
 from sentry.backup.helpers import ImportFlags
 from sentry.backup.scopes import ImportScope, RelocationScope
+from sentry.constants import ObjectStatus
 from sentry.db.models import (
     ArrayField,
+    BoundedPositiveIntegerField,
     FlexibleForeignKey,
     JSONField,
     Model,
@@ -740,6 +742,9 @@ class AlertRuleTriggerAction(AbstractNotificationAction):
 
     date_added = models.DateTimeField(default=timezone.now)
     sentry_app_config = JSONField(null=True)
+    status = BoundedPositiveIntegerField(
+        default=ObjectStatus.ACTIVE, choices=ObjectStatus.as_choices()
+    )
 
     class Meta:
         app_label = "sentry"

+ 47 - 0
src/sentry/migrations/0657_add_status_column_for_alert_rule_trigger_action.py

@@ -0,0 +1,47 @@
+# Generated by Django 5.0.2 on 2024-02-27 00:02
+
+from django.db import migrations
+
+import sentry.db.models.fields.bounded
+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", "0656_add_discover_dataset_split_dashboard"),
+    ]
+
+    operations = [
+        migrations.SeparateDatabaseAndState(
+            database_operations=[
+                migrations.RunSQL(
+                    """
+                    ALTER TABLE "sentry_alertruletriggeraction" ADD COLUMN "status" integer NOT NULL DEFAULT 0;
+                    """,
+                    reverse_sql="""
+                    ALTER TABLE "sentry_alertruletriggeraction" DROP COLUMN "status";
+                    """,
+                    hints={"tables": ["sentry_alertruletriggeraction"]},
+                ),
+            ],
+            state_operations=[
+                migrations.AddField(
+                    model_name="alertruletriggeraction",
+                    name="status",
+                    field=sentry.db.models.fields.bounded.BoundedPositiveIntegerField(default=0),
+                ),
+            ],
+        )
+    ]

+ 2 - 0
tests/sentry/backup/snapshots/ReleaseTests/test_at_head.pysnap

@@ -1441,6 +1441,7 @@ source: tests/sentry/backup/test_releases.py
     integration_id: null
     sentry_app_config: null
     sentry_app_id: null
+    status: 0
     target_display: null
     target_identifier: '3'
     target_type: 1
@@ -1453,6 +1454,7 @@ source: tests/sentry/backup/test_releases.py
     integration_id: null
     sentry_app_config: null
     sentry_app_id: null
+    status: 0
     target_display: null
     target_identifier: '3'
     target_type: 1