Skip to content

Commit 59f5d94

Browse files
authored
Remove excluded_projects & include_all_projects columns (#81204)
In preparation for removing the `AlertRuleExcludedProjects` model (see #81020) we need to first remove the many to many `excluded_projects` column on the `AlertRule` model. We can take the opportunity to remove the now unused `include_all_projects` column. This PR uses the brand new `SafeRemoveField` option added in #81098
1 parent 07809f0 commit 59f5d94

File tree

5 files changed

+47
-169
lines changed

5 files changed

+47
-169
lines changed

migrations_lockfile.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ remote_subscriptions: 0003_drop_remote_subscription
1515

1616
replays: 0004_index_together
1717

18-
sentry: 0793_remove_db_constraint_alert_rule_exclusion
18+
sentry: 0794_rm_excluded_included_projects_alertrule
1919

2020
social_auth: 0002_default_auto_field
2121

src/sentry/deletions/defaults/project.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def get_child_relations(self, instance: Project) -> list[BaseRelation]:
9393
relations.append(
9494
ModelRelation(
9595
AlertRule,
96-
{"snuba_query__subscriptions__project": instance, "include_all_projects": False},
96+
{"snuba_query__subscriptions__project": instance},
9797
)
9898
)
9999

src/sentry/incidents/models/alert_rule.py

-9
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,6 @@ class AlertRule(Model):
301301

302302
user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete="SET_NULL")
303303
team = FlexibleForeignKey("sentry.Team", null=True, on_delete=models.SET_NULL)
304-
305-
excluded_projects = models.ManyToManyField(
306-
"sentry.Project", related_name="alert_rule_exclusions", through=AlertRuleExcludedProjects
307-
) # NOTE: This feature is not currently utilized.
308-
# Determines whether we include all current and future projects from this
309-
# organization in this rule.
310-
include_all_projects = models.BooleanField(
311-
default=False
312-
) # NOTE: This feature is not currently utilized.
313304
name = models.TextField()
314305
status = models.SmallIntegerField(default=AlertRuleStatus.PENDING.value)
315306
threshold_type = models.SmallIntegerField(null=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Generated by Django 5.1.1 on 2024-11-22 19:12
2+
3+
from django.db import migrations, models
4+
5+
from sentry.new_migrations.migrations import CheckedMigration
6+
from sentry.new_migrations.monkey.fields import SafeRemoveField
7+
from sentry.new_migrations.monkey.state import DeletionAction
8+
9+
10+
class Migration(CheckedMigration):
11+
# This flag is used to mark that a migration shouldn't be automatically run in production.
12+
# This should only be used for operations where it's safe to run the migration after your
13+
# code has deployed. So this should not be used for most operations that alter the schema
14+
# of a table.
15+
# Here are some things that make sense to mark as post deployment:
16+
# - Large data migrations. Typically we want these to be run manually so that they can be
17+
# monitored and not block the deploy for a long period of time while they run.
18+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
19+
# run this outside deployments so that we don't block them. Note that while adding an index
20+
# is a schema change, it's completely safe to run the operation after the code has deployed.
21+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
22+
23+
is_post_deployment = False
24+
25+
dependencies = [
26+
("sentry", "0793_remove_db_constraint_alert_rule_exclusion"),
27+
]
28+
29+
operations = [
30+
SafeRemoveField(
31+
model_name="alertrule",
32+
name="excluded_projects",
33+
deletion_action=DeletionAction.MOVE_TO_PENDING,
34+
),
35+
migrations.AlterField(
36+
model_name="alertrule",
37+
name="include_all_projects",
38+
field=models.BooleanField(default=False, null=True),
39+
),
40+
SafeRemoveField(
41+
model_name="alertrule",
42+
name="include_all_projects",
43+
deletion_action=DeletionAction.MOVE_TO_PENDING,
44+
),
45+
]

tests/sentry/migrations/test_0730_add_subscription_fk_to_incident.py

-158
This file was deleted.

0 commit comments

Comments
 (0)