Repository: getsentry/sentry

Issue:
[BE] Write a migration to create the new `NeglectedAlert` table
- Make a new table `NeglectedAlert`
    - `rule_id` nullable False
    - `org_id`
    - `disable_date` will be “now” (when the script is run) + 14 days nullable False
    - `opted_out` boolean so when we re-run we don’t grab the same alert default False
    - `has_sent_initial_email` boolean default False
    - `has_sent_final_email` boolean default False


Discussion:

Resolving patch:
diff --git a/src/sentry/migrations/0552_create_neglectedalert_table.py b/src/sentry/migrations/0552_create_neglectedalert_table.py
new file mode 100644
--- /dev/null
+++ b/src/sentry/migrations/0552_create_neglectedalert_table.py
@@ -0,0 +1,59 @@
+# Generated by Django 3.2.20 on 2023-09-14 19:48
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+import sentry.db.models.fields.bounded
+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", "0551_drop_xactor_actor"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="NeglectedRule",
+            fields=[
+                (
+                    "id",
+                    sentry.db.models.fields.bounded.BoundedBigAutoField(
+                        primary_key=True, serialize=False
+                    ),
+                ),
+                ("disable_date", models.DateTimeField()),
+                ("opted_out", models.BooleanField(default=False)),
+                ("sent_initial_email_date", models.DateTimeField()),
+                ("sent_final_email_date", models.DateTimeField()),
+                (
+                    "organization",
+                    sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                        on_delete=django.db.models.deletion.CASCADE, to="sentry.organization"
+                    ),
+                ),
+                (
+                    "rule",
+                    sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                        on_delete=django.db.models.deletion.CASCADE, to="sentry.rule"
+                    ),
+                ),
+            ],
+            options={
+                "abstract": False,
+            },
+        ),
+    ]
diff --git a/src/sentry/models/rule.py b/src/sentry/models/rule.py
--- a/src/sentry/models/rule.py
+++ b/src/sentry/models/rule.py
@@ -130,3 +130,15 @@ class RuleActivity(Model):
     class Meta:
         app_label = "sentry"
         db_table = "sentry_ruleactivity"
+
+
+@region_silo_only_model
+class NeglectedRule(Model):
+    __relocation_scope__ = RelocationScope.Organization
+
+    rule = FlexibleForeignKey("sentry.Rule")
+    organization = FlexibleForeignKey("sentry.Organization")
+    disable_date = models.DateTimeField()
+    opted_out = models.BooleanField(default=False)
+    sent_initial_email_date = models.DateTimeField()
+    sent_final_email_date = models.DateTimeField()


Test patch:
diff --git a/tests/sentry/backup/test_models.py b/tests/sentry/backup/test_models.py
--- a/tests/sentry/backup/test_models.py
+++ b/tests/sentry/backup/test_models.py
@@ -66,7 +66,7 @@
 from sentry.models.recentsearch import RecentSearch
 from sentry.models.relay import Relay, RelayUsage
 from sentry.models.repository import Repository
-from sentry.models.rule import Rule, RuleActivity, RuleActivityType
+from sentry.models.rule import NeglectedRule, Rule, RuleActivity, RuleActivityType
 from sentry.models.rulesnooze import RuleSnooze
 from sentry.models.savedsearch import SavedSearch, Visibility
 from sentry.models.search_common import SearchType
@@ -439,7 +439,7 @@ def test_relay(self):
         RelayUsage.objects.create(relay_id=relay_id, version="0.0.1", public_key=public_key)
         return self.import_export_then_validate()
 
-    @targets(mark(Rule, RuleActivity, RuleSnooze))
+    @targets(mark(Rule, RuleActivity, RuleSnooze, NeglectedRule))
     def test_rule(self):
         rule = self.create_project_rule(project=self.project)
         RuleActivity.objects.create(rule=rule, type=RuleActivityType.CREATED.value)