|
| 1 | +# Generated by Django 3.2.20 on 2023-08-29 19:04 |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | + |
| 5 | +from sentry.new_migrations.migrations import CheckedMigration |
| 6 | +from sentry.utils.query import RangeQuerySetWrapperWithProgressBar |
| 7 | + |
| 8 | + |
| 9 | +def remove_name_data(apps, schema_editor): |
| 10 | + Rule = apps.get_model("sentry", "Rule") |
| 11 | + |
| 12 | + for rule in RangeQuerySetWrapperWithProgressBar(Rule.objects.all()): |
| 13 | + for action in rule.data.get("actions", []): |
| 14 | + if action.get("name") or action.get("name") in [0, ""]: |
| 15 | + del action["name"] |
| 16 | + |
| 17 | + for condition in rule.data.get("conditions", []): |
| 18 | + if condition.get("name") or condition.get("name") in [0, ""]: |
| 19 | + del condition["name"] |
| 20 | + |
| 21 | + rule.save(update_fields=["data"]) |
| 22 | + |
| 23 | + |
| 24 | +class Migration(CheckedMigration): |
| 25 | + # This flag is used to mark that a migration shouldn't be automatically run in production. For |
| 26 | + # the most part, this should only be used for operations where it's safe to run the migration |
| 27 | + # after your code has deployed. So this should not be used for most operations that alter the |
| 28 | + # schema of a table. |
| 29 | + # Here are some things that make sense to mark as dangerous: |
| 30 | + # - Large data migrations. Typically we want these to be run manually by ops so that they can |
| 31 | + # be monitored and not block the deploy for a long period of time while they run. |
| 32 | + # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to |
| 33 | + # have ops run this and not block the deploy. Note that while adding an index is a schema |
| 34 | + # change, it's completely safe to run the operation after the code has deployed. |
| 35 | + is_dangerous = True |
| 36 | + |
| 37 | + dependencies = [ |
| 38 | + ("sentry", "0537_backfill_xactor_team_and_user_ids"), |
| 39 | + ] |
| 40 | + |
| 41 | + operations = [ |
| 42 | + migrations.RunPython( |
| 43 | + remove_name_data, |
| 44 | + migrations.RunPython.noop, |
| 45 | + hints={"tables": ["sentry_rule"]}, |
| 46 | + ), |
| 47 | + ] |
0 commit comments