diff --git a/src/sentry/migrations/0549_migrate_no_action_dupe_issue_alerts.py b/src/sentry/migrations/0549_migrate_no_action_dupe_issue_alerts.py deleted file mode 100644 index 6e9d53be766439..00000000000000 --- a/src/sentry/migrations/0549_migrate_no_action_dupe_issue_alerts.py +++ /dev/null @@ -1,92 +0,0 @@ -# Generated by Django 3.2.20 on 2023-09-11 19:11 - -from django.db import migrations - -from sentry.new_migrations.migrations import CheckedMigration -from sentry.utils.query import RangeQuerySetWrapperWithProgressBar - - -class ObjectStatus: - ACTIVE = 0 - HIDDEN = 1 - PENDING_DELETION = 2 - DELETION_IN_PROGRESS = 3 - - DISABLED = 1 - - -def has_duplicate_rule(apps, rule_data, project, rule_id): - Rule = apps.get_model("sentry", "Rule") - - matchers = {key for key in list(rule_data.keys()) if key not in ("name", "user_id")} - extra_fields = ["actions", "environment"] - matchers.update(extra_fields) - existing_rules = Rule.objects.exclude(id=rule_id).filter( - project=project, status=ObjectStatus.ACTIVE - ) - for existing_rule in existing_rules: - keys = 0 - matches = 0 - for matcher in matchers: - if existing_rule.data.get(matcher) and rule_data.get(matcher): - keys += 1 - - if existing_rule.data[matcher] == rule_data[matcher]: - matches += 1 - - elif matcher in extra_fields: - if not existing_rule.data.get(matcher) and not rule_data.get(matcher): - # neither rule has the matcher - continue - - elif matcher == "environment": - if existing_rule.environment_id and rule_data.get(matcher): - keys += 1 - if existing_rule.environment_id == rule_data.get(matcher): - matches += 1 - else: - keys += 1 - else: - # one rule has the matcher and the other one doesn't - keys += 1 - - if keys == matches: - return True - return False - - -def migrate_bad_rules(apps, schema_editor): - Rule = apps.get_model("sentry", "Rule") - - for rule in RangeQuerySetWrapperWithProgressBar(Rule.objects.all()): - if not rule.data.get("actions", []) or has_duplicate_rule( - apps, rule.data, rule.project, rule.id - ): - rule.status = ObjectStatus.DISABLED - rule.save(update_fields=["status"]) - - -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 = True - - dependencies = [ - ("sentry", "0548_add_is_unclaimed_boolean_to_user"), - ] - - operations = [ - migrations.RunPython( - migrate_bad_rules, - migrations.RunPython.noop, - hints={"tables": ["sentry_rule"]}, - ), - ]