|
| 1 | +# Generated by Django 5.2.8 on 2026-01-08 18:18 |
| 2 | + |
| 3 | +import django.contrib.postgres.fields |
| 4 | +from django.db import migrations, models |
| 5 | +from django.db.backends.base.schema import BaseDatabaseSchemaEditor |
| 6 | +from django.db.migrations.state import StateApps |
| 7 | + |
| 8 | +from sentry.new_migrations.migrations import CheckedMigration |
| 9 | + |
| 10 | + |
| 11 | +def remove_on_command_phrase_from_repository_settings( |
| 12 | + apps: StateApps, schema_editor: BaseDatabaseSchemaEditor |
| 13 | +) -> None: |
| 14 | + """Remove 'on_command_phrase' from RepositorySettings.code_review_triggers.""" |
| 15 | + RepositorySettings = apps.get_model("sentry", "RepositorySettings") |
| 16 | + |
| 17 | + all_settings = list(RepositorySettings.objects.all()) |
| 18 | + |
| 19 | + updated_settings = [] |
| 20 | + for settings in all_settings: |
| 21 | + if ( |
| 22 | + settings.code_review_triggers |
| 23 | + and isinstance(settings.code_review_triggers, list) |
| 24 | + and "on_command_phrase" in settings.code_review_triggers |
| 25 | + ): |
| 26 | + settings.code_review_triggers = [ |
| 27 | + trigger |
| 28 | + for trigger in settings.code_review_triggers |
| 29 | + if trigger != "on_command_phrase" |
| 30 | + ] |
| 31 | + updated_settings.append(settings) |
| 32 | + |
| 33 | + if updated_settings: |
| 34 | + RepositorySettings.objects.bulk_update(updated_settings, fields=["code_review_triggers"]) |
| 35 | + |
| 36 | + |
| 37 | +class Migration(CheckedMigration): |
| 38 | + # This flag is used to mark that a migration shouldn't be automatically run in production. |
| 39 | + # This should only be used for operations where it's safe to run the migration after your |
| 40 | + # code has deployed. So this should not be used for most operations that alter the schema |
| 41 | + # of a table. |
| 42 | + # Here are some things that make sense to mark as post deployment: |
| 43 | + # - Large data migrations. Typically we want these to be run manually so that they can be |
| 44 | + # monitored and not block the deploy for a long period of time while they run. |
| 45 | + # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to |
| 46 | + # run this outside deployments so that we don't block them. Note that while adding an index |
| 47 | + # is a schema change, it's completely safe to run the operation after the code has deployed. |
| 48 | + # Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment |
| 49 | + |
| 50 | + is_post_deployment = False |
| 51 | + |
| 52 | + dependencies = [ |
| 53 | + ("sentry", "1015_backfill_self_hosted_sentry_app_emails"), |
| 54 | + ] |
| 55 | + |
| 56 | + operations = [ |
| 57 | + migrations.RunPython( |
| 58 | + remove_on_command_phrase_from_repository_settings, |
| 59 | + reverse_code=migrations.RunPython.noop, |
| 60 | + hints={"tables": ["sentry_repositorysettings"]}, |
| 61 | + ), |
| 62 | + migrations.AlterField( |
| 63 | + model_name="repositorysettings", |
| 64 | + name="code_review_triggers", |
| 65 | + field=django.contrib.postgres.fields.ArrayField( |
| 66 | + base_field=models.CharField( |
| 67 | + choices=[ |
| 68 | + ("on_new_commit", "on_new_commit"), |
| 69 | + ("on_ready_for_review", "on_ready_for_review"), |
| 70 | + ], |
| 71 | + max_length=32, |
| 72 | + ), |
| 73 | + default=list, |
| 74 | + ), |
| 75 | + ), |
| 76 | + ] |
0 commit comments