diff --git a/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/__init__.py b/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/migrations/0001_initial.py b/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/migrations/0001_initial.py new file mode 100644 index 00000000000000..8d119afd028622 --- /dev/null +++ b/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/migrations/0001_initial.py @@ -0,0 +1,16 @@ +# Generated by Django 3.1 on 2019-09-22 21:47 + +from django.db import migrations + +from sentry.new_migrations.migrations import CheckedMigration + + +class Migration(CheckedMigration): + + initial = True + + dependencies = [] + + allow_run_sql = False + + operations = [migrations.RunSQL("select 1;")] diff --git a/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/migrations/__init__.py b/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/migrations/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/models.py b/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/models.py new file mode 100644 index 00000000000000..770fa149c355ce --- /dev/null +++ b/fixtures/safe_migrations_apps/bad_flow_run_sql_disabled_app/models.py @@ -0,0 +1,5 @@ +from django.db import models + + +class TestTable(models.Model): + field = models.IntegerField(default=0, null=False) diff --git a/fixtures/safe_migrations_apps/good_flow_delete_model_state_app/migrations/0002_delete_model_state.py b/fixtures/safe_migrations_apps/good_flow_delete_model_state_app/migrations/0002_delete_model_state.py index aa7a0b3105125d..4d9779f1c977f0 100644 --- a/fixtures/safe_migrations_apps/good_flow_delete_model_state_app/migrations/0002_delete_model_state.py +++ b/fixtures/safe_migrations_apps/good_flow_delete_model_state_app/migrations/0002_delete_model_state.py @@ -1,8 +1,7 @@ # Generated by Django 3.1 on 2019-09-22 21:47 - -from django.db import migrations - from sentry.new_migrations.migrations import CheckedMigration +from sentry.new_migrations.monkey.models import SafeDeleteModel +from sentry.new_migrations.monkey.state import DeletionAction class Migration(CheckedMigration): @@ -12,11 +11,5 @@ class Migration(CheckedMigration): ] operations = [ - migrations.SeparateDatabaseAndState( - state_operations=[ - migrations.DeleteModel( - name="TestTable", - ), - ] - ) + SafeDeleteModel(name="TestTable", deletion_action=DeletionAction.MOVE_TO_PENDING), ] diff --git a/fixtures/safe_migrations_apps/good_flow_delete_model_state_app/migrations/0003_delete_table.py b/fixtures/safe_migrations_apps/good_flow_delete_model_state_app/migrations/0003_delete_table.py index f0a85b49040a3e..8a6e05080a31bc 100644 --- a/fixtures/safe_migrations_apps/good_flow_delete_model_state_app/migrations/0003_delete_table.py +++ b/fixtures/safe_migrations_apps/good_flow_delete_model_state_app/migrations/0003_delete_table.py @@ -1,16 +1,15 @@ # Generated by Django 3.1 on 2019-09-22 21:47 - -from django.db import migrations - from sentry.new_migrations.migrations import CheckedMigration +from sentry.new_migrations.monkey.models import SafeDeleteModel +from sentry.new_migrations.monkey.state import DeletionAction class Migration(CheckedMigration): dependencies = [ - ("good_flow_delete_model_state_app", "0001_initial"), + ("good_flow_delete_model_state_app", "0002_delete_model_state"), ] operations = [ - migrations.RunSQL('DROP TABLE "good_flow_delete_model_state_app_testtable";'), + SafeDeleteModel(name="TestTable", deletion_action=DeletionAction.DELETE), ] diff --git a/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/__init__.py b/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/migrations/0001_initial.py b/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/migrations/0001_initial.py new file mode 100644 index 00000000000000..8939a5ba3393b7 --- /dev/null +++ b/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/migrations/0001_initial.py @@ -0,0 +1,16 @@ +# Generated by Django 3.1 on 2019-09-22 21:47 + +from django.db import migrations + +from sentry.new_migrations.migrations import CheckedMigration + + +class Migration(CheckedMigration): + + initial = True + + dependencies = [] + + allow_run_sql = True + + operations = [migrations.RunSQL("select 1;")] diff --git a/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/migrations/__init__.py b/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/migrations/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/models.py b/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/models.py new file mode 100644 index 00000000000000..770fa149c355ce --- /dev/null +++ b/fixtures/safe_migrations_apps/good_flow_run_sql_enabled_app/models.py @@ -0,0 +1,5 @@ +from django.db import models + + +class TestTable(models.Model): + field = models.IntegerField(default=0, null=False) diff --git a/src/sentry/hybridcloud/migrations/0003_add_scopes_to_api_key_replica.py b/src/sentry/hybridcloud/migrations/0003_add_scopes_to_api_key_replica.py index 320d680a87853f..092ed71bbc5cc9 100644 --- a/src/sentry/hybridcloud/migrations/0003_add_scopes_to_api_key_replica.py +++ b/src/sentry/hybridcloud/migrations/0003_add_scopes_to_api_key_replica.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("hybridcloud", "0002_add_slug_reservation_replica_model"), ] diff --git a/src/sentry/migrations/0001_squashed_0484_break_org_member_user_fk.py b/src/sentry/migrations/0001_squashed_0484_break_org_member_user_fk.py index 5592f4a25a27a5..16ef15658ea34a 100644 --- a/src/sentry/migrations/0001_squashed_0484_break_org_member_user_fk.py +++ b/src/sentry/migrations/0001_squashed_0484_break_org_member_user_fk.py @@ -54,6 +54,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + replaces = [ ("sentry", "0001_squashed_0200_release_indices"), ("sentry", "0201_semver_package"), diff --git a/src/sentry/migrations/0490_add_is_test_to_org.py b/src/sentry/migrations/0490_add_is_test_to_org.py index 5ea600ad4cf024..398394ba1409cb 100644 --- a/src/sentry/migrations/0490_add_is_test_to_org.py +++ b/src/sentry/migrations/0490_add_is_test_to_org.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0489_index_checkin_timeout"), ] diff --git a/src/sentry/migrations/0491_remove_orgmemmap_unique_constraints.py b/src/sentry/migrations/0491_remove_orgmemmap_unique_constraints.py index a239fb98237803..4e30ad2812ad4c 100644 --- a/src/sentry/migrations/0491_remove_orgmemmap_unique_constraints.py +++ b/src/sentry/migrations/0491_remove_orgmemmap_unique_constraints.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0490_add_is_test_to_org"), ] diff --git a/src/sentry/migrations/0505_debugfile_date_accessed.py b/src/sentry/migrations/0505_debugfile_date_accessed.py index c39b0755a95d94..ff60d15fe6bbad 100644 --- a/src/sentry/migrations/0505_debugfile_date_accessed.py +++ b/src/sentry/migrations/0505_debugfile_date_accessed.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0504_add_artifact_bundle_index"), ] diff --git a/src/sentry/migrations/0526_pr_comment_type_column.py b/src/sentry/migrations/0526_pr_comment_type_column.py index 3bfa0f8575e774..1791094fdecd7d 100644 --- a/src/sentry/migrations/0526_pr_comment_type_column.py +++ b/src/sentry/migrations/0526_pr_comment_type_column.py @@ -21,6 +21,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0525_add_next_checkin_latest"), ] diff --git a/src/sentry/migrations/0535_add_created_date_to_outbox_model.py b/src/sentry/migrations/0535_add_created_date_to_outbox_model.py index 179daa393d1816..abff5766528167 100644 --- a/src/sentry/migrations/0535_add_created_date_to_outbox_model.py +++ b/src/sentry/migrations/0535_add_created_date_to_outbox_model.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0534_add_notification_uuid_to_rule_fire_history"), ] diff --git a/src/sentry/migrations/0544_remove_groupsubscription_columns.py b/src/sentry/migrations/0544_remove_groupsubscription_columns.py index 10f92624209879..bc6ad90444e2d2 100644 --- a/src/sentry/migrations/0544_remove_groupsubscription_columns.py +++ b/src/sentry/migrations/0544_remove_groupsubscription_columns.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0543_add_team_id_to_groupsubscription"), ] diff --git a/src/sentry/migrations/0545_add_last_verified_auth_ident_replica.py b/src/sentry/migrations/0545_add_last_verified_auth_ident_replica.py index b24ed739818100..71a4ebafc20939 100644 --- a/src/sentry/migrations/0545_add_last_verified_auth_ident_replica.py +++ b/src/sentry/migrations/0545_add_last_verified_auth_ident_replica.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0544_remove_groupsubscription_columns"), ] diff --git a/src/sentry/migrations/0548_add_is_unclaimed_boolean_to_user.py b/src/sentry/migrations/0548_add_is_unclaimed_boolean_to_user.py index 324603794f7859..6e2ae095940622 100644 --- a/src/sentry/migrations/0548_add_is_unclaimed_boolean_to_user.py +++ b/src/sentry/migrations/0548_add_is_unclaimed_boolean_to_user.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0547_add_commitfilechange_language_column"), ] diff --git a/src/sentry/migrations/0549_re_add_groupsubscription_columns.py b/src/sentry/migrations/0549_re_add_groupsubscription_columns.py index f124f9337c4f8f..4468a981c603bf 100644 --- a/src/sentry/migrations/0549_re_add_groupsubscription_columns.py +++ b/src/sentry/migrations/0549_re_add_groupsubscription_columns.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = True + allow_run_sql = True + dependencies = [ ("sentry", "0548_add_is_unclaimed_boolean_to_user"), ] diff --git a/src/sentry/migrations/0556_organizationmapping_replicate_require_2fa.py b/src/sentry/migrations/0556_organizationmapping_replicate_require_2fa.py index e249bd0d688fd4..3185e6373b831d 100644 --- a/src/sentry/migrations/0556_organizationmapping_replicate_require_2fa.py +++ b/src/sentry/migrations/0556_organizationmapping_replicate_require_2fa.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0555_set_neglectedrule_email_date_columns_nullable"), ] diff --git a/src/sentry/migrations/0564_commitfilechange_delete_language_column.py b/src/sentry/migrations/0564_commitfilechange_delete_language_column.py index c29268441b68d4..9a5cc11a0d9ee6 100644 --- a/src/sentry/migrations/0564_commitfilechange_delete_language_column.py +++ b/src/sentry/migrations/0564_commitfilechange_delete_language_column.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0563_commitfilechange_drop_language_column"), ] diff --git a/src/sentry/migrations/0570_repository_add_languages_column.py b/src/sentry/migrations/0570_repository_add_languages_column.py index 8d61069af4bbdb..9b7cd95383156f 100644 --- a/src/sentry/migrations/0570_repository_add_languages_column.py +++ b/src/sentry/migrations/0570_repository_add_languages_column.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0569_dashboard_widgets_indicator"), ] diff --git a/src/sentry/migrations/0583_add_early_adopter_to_organization_mapping.py b/src/sentry/migrations/0583_add_early_adopter_to_organization_mapping.py index 8d87de590a53d8..5641c4e1d47a1d 100644 --- a/src/sentry/migrations/0583_add_early_adopter_to_organization_mapping.py +++ b/src/sentry/migrations/0583_add_early_adopter_to_organization_mapping.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0582_add_status_indexes_checkins"), ] diff --git a/src/sentry/migrations/0590_add_metadata_to_sentry_app.py b/src/sentry/migrations/0590_add_metadata_to_sentry_app.py index 70467066f7a0b4..17c605b63b648b 100644 --- a/src/sentry/migrations/0590_add_metadata_to_sentry_app.py +++ b/src/sentry/migrations/0590_add_metadata_to_sentry_app.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0589_add_commit_date_added_indices"), ] diff --git a/src/sentry/migrations/0591_remove_relocation_hybrid_cloud_foreign_keys.py b/src/sentry/migrations/0591_remove_relocation_hybrid_cloud_foreign_keys.py index 9504b752d61bef..d4702555a72981 100644 --- a/src/sentry/migrations/0591_remove_relocation_hybrid_cloud_foreign_keys.py +++ b/src/sentry/migrations/0591_remove_relocation_hybrid_cloud_foreign_keys.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0590_add_metadata_to_sentry_app"), ] diff --git a/src/sentry/migrations/0592_delete_relocation_hybrid_cloud_foreign_keys.py b/src/sentry/migrations/0592_delete_relocation_hybrid_cloud_foreign_keys.py index f184baa6f83908..6ce84ad9f211e1 100644 --- a/src/sentry/migrations/0592_delete_relocation_hybrid_cloud_foreign_keys.py +++ b/src/sentry/migrations/0592_delete_relocation_hybrid_cloud_foreign_keys.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0591_remove_relocation_hybrid_cloud_foreign_keys"), ] diff --git a/src/sentry/migrations/0607_drop_externalactor_actorid.py b/src/sentry/migrations/0607_drop_externalactor_actorid.py index 6f7bf3fd118686..6052d52bb1aa2f 100644 --- a/src/sentry/migrations/0607_drop_externalactor_actorid.py +++ b/src/sentry/migrations/0607_drop_externalactor_actorid.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0606_update_user_to_optional_organization_slug_reservation"), ] diff --git a/src/sentry/migrations/0610_remove_notification_setting_table.py b/src/sentry/migrations/0610_remove_notification_setting_table.py index 47dfb155e353ac..e88cf1a990ec60 100644 --- a/src/sentry/migrations/0610_remove_notification_setting_table.py +++ b/src/sentry/migrations/0610_remove_notification_setting_table.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0609_remove_notification_setting_model"), ] diff --git a/src/sentry/migrations/0617_monitor_boolean_fields_muted_disabled.py b/src/sentry/migrations/0617_monitor_boolean_fields_muted_disabled.py index fe25887609f43f..040d95c6bfcce5 100644 --- a/src/sentry/migrations/0617_monitor_boolean_fields_muted_disabled.py +++ b/src/sentry/migrations/0617_monitor_boolean_fields_muted_disabled.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0616_drop_event_user_id_from_userreport_table_step_1"), ] diff --git a/src/sentry/migrations/0618_drop_event_user_id_from_userreport_table_step_2.py b/src/sentry/migrations/0618_drop_event_user_id_from_userreport_table_step_2.py index 0a2d77ed6ca01d..60c5c7d3c100c6 100644 --- a/src/sentry/migrations/0618_drop_event_user_id_from_userreport_table_step_2.py +++ b/src/sentry/migrations/0618_drop_event_user_id_from_userreport_table_step_2.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0617_monitor_boolean_fields_muted_disabled"), ] diff --git a/src/sentry/migrations/0624_add_is_muted_monitorenvironment.py b/src/sentry/migrations/0624_add_is_muted_monitorenvironment.py index 9d36e7039b1533..28437b53203c1b 100644 --- a/src/sentry/migrations/0624_add_is_muted_monitorenvironment.py +++ b/src/sentry/migrations/0624_add_is_muted_monitorenvironment.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0623_increase_regression_fingerprint_length"), ] diff --git a/src/sentry/migrations/0631_add_priority_columns_to_groupedmessage.py b/src/sentry/migrations/0631_add_priority_columns_to_groupedmessage.py index fdad116dc7ee45..6dffdce9d51f16 100644 --- a/src/sentry/migrations/0631_add_priority_columns_to_groupedmessage.py +++ b/src/sentry/migrations/0631_add_priority_columns_to_groupedmessage.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0630_better_monitor_latest_index"), ] diff --git a/src/sentry/migrations/0633_add_priority_locked_at_to_groupedmessage.py b/src/sentry/migrations/0633_add_priority_locked_at_to_groupedmessage.py index f0639df01f5e08..25c185d4151429 100644 --- a/src/sentry/migrations/0633_add_priority_locked_at_to_groupedmessage.py +++ b/src/sentry/migrations/0633_add_priority_locked_at_to_groupedmessage.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0632_apitoken_backfill_last_chars"), ] diff --git a/src/sentry/migrations/0637_remove_pr_comment_pr_id_constraint.py b/src/sentry/migrations/0637_remove_pr_comment_pr_id_constraint.py index 2c7a45b552bbf6..c06a425026ca2f 100644 --- a/src/sentry/migrations/0637_remove_pr_comment_pr_id_constraint.py +++ b/src/sentry/migrations/0637_remove_pr_comment_pr_id_constraint.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0636_monitor_incident_env_resolving_index"), ] diff --git a/src/sentry/migrations/0638_add_date_added_to_dashboard_widget_on_demand.py b/src/sentry/migrations/0638_add_date_added_to_dashboard_widget_on_demand.py index dc5e9246bdb970..b759ff0f296f58 100644 --- a/src/sentry/migrations/0638_add_date_added_to_dashboard_widget_on_demand.py +++ b/src/sentry/migrations/0638_add_date_added_to_dashboard_widget_on_demand.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0637_remove_pr_comment_pr_id_constraint"), ] diff --git a/src/sentry/migrations/0643_add_date_modified_col_dashboard_widget_query.py b/src/sentry/migrations/0643_add_date_modified_col_dashboard_widget_query.py index 1c6498a4817afc..09068d38850701 100644 --- a/src/sentry/migrations/0643_add_date_modified_col_dashboard_widget_query.py +++ b/src/sentry/migrations/0643_add_date_modified_col_dashboard_widget_query.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0642_index_together_release"), ] diff --git a/src/sentry/migrations/0651_enable_activated_alert_rules.py b/src/sentry/migrations/0651_enable_activated_alert_rules.py index 60408e2a6f4779..4e1d2640b9edc3 100644 --- a/src/sentry/migrations/0651_enable_activated_alert_rules.py +++ b/src/sentry/migrations/0651_enable_activated_alert_rules.py @@ -23,6 +23,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0650_create_sentryshot"), ] diff --git a/src/sentry/migrations/0657_add_status_column_for_alert_rule_trigger_action.py b/src/sentry/migrations/0657_add_status_column_for_alert_rule_trigger_action.py index d1d5dc69bbc3d6..31fbdf83276a70 100644 --- a/src/sentry/migrations/0657_add_status_column_for_alert_rule_trigger_action.py +++ b/src/sentry/migrations/0657_add_status_column_for_alert_rule_trigger_action.py @@ -19,6 +19,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0656_add_discover_dataset_split_dashboard"), ] diff --git a/src/sentry/migrations/0658_projectkey_usecase.py b/src/sentry/migrations/0658_projectkey_usecase.py index 721f564704bce8..84964091d4aa0d 100644 --- a/src/sentry/migrations/0658_projectkey_usecase.py +++ b/src/sentry/migrations/0658_projectkey_usecase.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0657_add_status_column_for_alert_rule_trigger_action"), ] diff --git a/src/sentry/migrations/0663_artifactbundleindex_cleanup_step3.py b/src/sentry/migrations/0663_artifactbundleindex_cleanup_step3.py index 70ec590c959b64..670b5d9aa5bb6f 100644 --- a/src/sentry/migrations/0663_artifactbundleindex_cleanup_step3.py +++ b/src/sentry/migrations/0663_artifactbundleindex_cleanup_step3.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0662_monitor_drop_last_state_change"), ] diff --git a/src/sentry/migrations/0665_monitor_drop_last_state_change_db.py b/src/sentry/migrations/0665_monitor_drop_last_state_change_db.py index dbef628771474b..56e9a741d8020a 100644 --- a/src/sentry/migrations/0665_monitor_drop_last_state_change_db.py +++ b/src/sentry/migrations/0665_monitor_drop_last_state_change_db.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0664_create_new_broken_monitor_detection_table"), ] diff --git a/src/sentry/migrations/0678_add_is_hidden_dashboard_widget_query.py b/src/sentry/migrations/0678_add_is_hidden_dashboard_widget_query.py index d45b47230af02f..6f6fb4a07250d5 100644 --- a/src/sentry/migrations/0678_add_is_hidden_dashboard_widget_query.py +++ b/src/sentry/migrations/0678_add_is_hidden_dashboard_widget_query.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0677_unpickle_project_options_again"), ] diff --git a/src/sentry/migrations/0682_monitors_constrain_to_project_id_slug.py b/src/sentry/migrations/0682_monitors_constrain_to_project_id_slug.py index c6a78343712ecf..1bf094a1582093 100644 --- a/src/sentry/migrations/0682_monitors_constrain_to_project_id_slug.py +++ b/src/sentry/migrations/0682_monitors_constrain_to_project_id_slug.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = True + allow_run_sql = True + dependencies = [ ("sentry", "0681_unpickle_authenticator_again"), ] diff --git a/src/sentry/migrations/0689_drop_config_from_cron_checkin.py b/src/sentry/migrations/0689_drop_config_from_cron_checkin.py index 724035f46302cf..e2165fe3b044b8 100644 --- a/src/sentry/migrations/0689_drop_config_from_cron_checkin.py +++ b/src/sentry/migrations/0689_drop_config_from_cron_checkin.py @@ -18,6 +18,8 @@ class Migration(CheckedMigration): # change, it's completely safe to run the operation after the code has deployed. is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0688_add_project_flag_high_priority_alerts"), ] diff --git a/src/sentry/migrations/0697_remove_monitor_owner_actor_id_db.py b/src/sentry/migrations/0697_remove_monitor_owner_actor_id_db.py index 6f09d09c5c55af..837d74f0dd3f44 100644 --- a/src/sentry/migrations/0697_remove_monitor_owner_actor_id_db.py +++ b/src/sentry/migrations/0697_remove_monitor_owner_actor_id_db.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0696_remove_monitor_owner_actor_id"), ] diff --git a/src/sentry/migrations/0700_drop_fileid_controlavatar.py b/src/sentry/migrations/0700_drop_fileid_controlavatar.py index 0df209ea2d5de8..2e0607e567795c 100644 --- a/src/sentry/migrations/0700_drop_fileid_controlavatar.py +++ b/src/sentry/migrations/0700_drop_fileid_controlavatar.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0699_update_monitor_owner_team_id_cascsade"), ] diff --git a/src/sentry/migrations/0707_alert_rule_activations_incidents_fk.py b/src/sentry/migrations/0707_alert_rule_activations_incidents_fk.py index ff7a700e1aa93b..084f37f4732178 100644 --- a/src/sentry/migrations/0707_alert_rule_activations_incidents_fk.py +++ b/src/sentry/migrations/0707_alert_rule_activations_incidents_fk.py @@ -22,6 +22,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0706_grouphistory_userteam_backfill"), ] diff --git a/src/sentry/migrations/0709_alertrule_remove_owner_state.py b/src/sentry/migrations/0709_alertrule_remove_owner_state.py index 4eb13999d671c1..8123ffc5f80607 100644 --- a/src/sentry/migrations/0709_alertrule_remove_owner_state.py +++ b/src/sentry/migrations/0709_alertrule_remove_owner_state.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0708_rule_remove_owner_state"), ] diff --git a/src/sentry/migrations/0710_grouphistory_remove_actor_state.py b/src/sentry/migrations/0710_grouphistory_remove_actor_state.py index b011bcbde62c45..59e4bdb5806122 100644 --- a/src/sentry/migrations/0710_grouphistory_remove_actor_state.py +++ b/src/sentry/migrations/0710_grouphistory_remove_actor_state.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0709_alertrule_remove_owner_state"), ] diff --git a/src/sentry/migrations/0713_team_remove_actor_state.py b/src/sentry/migrations/0713_team_remove_actor_state.py index 84a80d3fe1d029..f4c773750cfd7f 100644 --- a/src/sentry/migrations/0713_team_remove_actor_state.py +++ b/src/sentry/migrations/0713_team_remove_actor_state.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0712_create_tombstone_compound_indexes"), ] diff --git a/src/sentry/migrations/0714_drop_project_team_avatar.py b/src/sentry/migrations/0714_drop_project_team_avatar.py index 73e0438f7c58bb..7e3a5b6623364f 100644 --- a/src/sentry/migrations/0714_drop_project_team_avatar.py +++ b/src/sentry/migrations/0714_drop_project_team_avatar.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0713_team_remove_actor_state"), ] diff --git a/src/sentry/migrations/0715_remove_actormodel_constraints.py b/src/sentry/migrations/0715_remove_actormodel_constraints.py index cd87515e7ed464..9b9eb125d0a456 100644 --- a/src/sentry/migrations/0715_remove_actormodel_constraints.py +++ b/src/sentry/migrations/0715_remove_actormodel_constraints.py @@ -22,6 +22,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0714_drop_project_team_avatar"), ] diff --git a/src/sentry/migrations/0719_querysubscription_timebox_column_deletion_db.py b/src/sentry/migrations/0719_querysubscription_timebox_column_deletion_db.py index 59ca6933a64ed6..718648afa84e14 100644 --- a/src/sentry/migrations/0719_querysubscription_timebox_column_deletion_db.py +++ b/src/sentry/migrations/0719_querysubscription_timebox_column_deletion_db.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0718_delete_timebox_columns"), ] diff --git a/src/sentry/migrations/0720_remove_actor_columns.py b/src/sentry/migrations/0720_remove_actor_columns.py index 6b098b9ebddbcb..add6252e7b4805 100644 --- a/src/sentry/migrations/0720_remove_actor_columns.py +++ b/src/sentry/migrations/0720_remove_actor_columns.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0719_querysubscription_timebox_column_deletion_db"), ] diff --git a/src/sentry/migrations/0722_drop_sentryfunctions.py b/src/sentry/migrations/0722_drop_sentryfunctions.py index 8e0bcd9ece8416..bf0357c3fb98d3 100644 --- a/src/sentry/migrations/0722_drop_sentryfunctions.py +++ b/src/sentry/migrations/0722_drop_sentryfunctions.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0721_delete_sentryfunctions"), ] diff --git a/src/sentry/migrations/0724_discover_saved_query_dataset.py b/src/sentry/migrations/0724_discover_saved_query_dataset.py index c8439d7e2261d2..0dbf432449a084 100644 --- a/src/sentry/migrations/0724_discover_saved_query_dataset.py +++ b/src/sentry/migrations/0724_discover_saved_query_dataset.py @@ -21,6 +21,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0723_project_template_models"), ] diff --git a/src/sentry/migrations/0725_create_sentry_groupsearchview_table.py b/src/sentry/migrations/0725_create_sentry_groupsearchview_table.py index 40120a0f0db007..eecb7007bcafa9 100644 --- a/src/sentry/migrations/0725_create_sentry_groupsearchview_table.py +++ b/src/sentry/migrations/0725_create_sentry_groupsearchview_table.py @@ -26,6 +26,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0724_discover_saved_query_dataset"), ] diff --git a/src/sentry/migrations/0733_relocation_provenance.py b/src/sentry/migrations/0733_relocation_provenance.py index 9600cfa7b7f2c8..72626606c5ca6e 100644 --- a/src/sentry/migrations/0733_relocation_provenance.py +++ b/src/sentry/migrations/0733_relocation_provenance.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0732_add_span_attribute_extraction_rules"), ] diff --git a/src/sentry/migrations/0737_add_discover_saved_query_dataset_source.py b/src/sentry/migrations/0737_add_discover_saved_query_dataset_source.py index d3d14ff0930995..02ea18a44e3410 100644 --- a/src/sentry/migrations/0737_add_discover_saved_query_dataset_source.py +++ b/src/sentry/migrations/0737_add_discover_saved_query_dataset_source.py @@ -21,6 +21,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0736_rm_reprocessing_step2"), ] diff --git a/src/sentry/migrations/0738_rm_reprocessing_step3.py b/src/sentry/migrations/0738_rm_reprocessing_step3.py index ed23fac78edb47..de7cde8e7701bb 100644 --- a/src/sentry/migrations/0738_rm_reprocessing_step3.py +++ b/src/sentry/migrations/0738_rm_reprocessing_step3.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0737_add_discover_saved_query_dataset_source"), ] diff --git a/src/sentry/migrations/0741_metric_alert_anomaly_detection.py b/src/sentry/migrations/0741_metric_alert_anomaly_detection.py index 3e8d7f3aeda955..86eb1ba26927a5 100644 --- a/src/sentry/migrations/0741_metric_alert_anomaly_detection.py +++ b/src/sentry/migrations/0741_metric_alert_anomaly_detection.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0740_one_relocation_file_kind_per_relocation"), ] diff --git a/src/sentry/migrations/0744_add_dataset_source_field_to_dashboards.py b/src/sentry/migrations/0744_add_dataset_source_field_to_dashboards.py index 47159802485e5d..de09cf3ff0abee 100644 --- a/src/sentry/migrations/0744_add_dataset_source_field_to_dashboards.py +++ b/src/sentry/migrations/0744_add_dataset_source_field_to_dashboards.py @@ -21,6 +21,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0743_backfill_broken_monitor_notification_setting_option"), ] diff --git a/src/sentry/migrations/0746_add_bitflags_to_hybrid_cloud.py b/src/sentry/migrations/0746_add_bitflags_to_hybrid_cloud.py index 0c577fe5630a9e..9dad268ac936f7 100644 --- a/src/sentry/migrations/0746_add_bitflags_to_hybrid_cloud.py +++ b/src/sentry/migrations/0746_add_bitflags_to_hybrid_cloud.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0745_add_prevent_superuser_access_bitflag"), ] diff --git a/src/sentry/migrations/0750_disable_member_invite_in_hybrid_cloud.py b/src/sentry/migrations/0750_disable_member_invite_in_hybrid_cloud.py index fcb366e642b1df..3eb750ff9d496b 100644 --- a/src/sentry/migrations/0750_disable_member_invite_in_hybrid_cloud.py +++ b/src/sentry/migrations/0750_disable_member_invite_in_hybrid_cloud.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0749_disable_member_invite"), ] diff --git a/src/sentry/migrations/0757_add_scopes_to_apiapplication.py b/src/sentry/migrations/0757_add_scopes_to_apiapplication.py index e0851898bf17ab..074c9ce950dc69 100644 --- a/src/sentry/migrations/0757_add_scopes_to_apiapplication.py +++ b/src/sentry/migrations/0757_add_scopes_to_apiapplication.py @@ -21,6 +21,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0756_grouprelease_represented_in_django"), ] diff --git a/src/sentry/migrations/0759_remove_spanattributeextraction_tables.py b/src/sentry/migrations/0759_remove_spanattributeextraction_tables.py index d778dbf7def58d..aba74fb7c586e3 100644 --- a/src/sentry/migrations/0759_remove_spanattributeextraction_tables.py +++ b/src/sentry/migrations/0759_remove_spanattributeextraction_tables.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0758_remove_spanattributeextraction_models"), ] diff --git a/src/sentry/migrations/0760_remove_appstore_connect_integration_tables.py b/src/sentry/migrations/0760_remove_appstore_connect_integration_tables.py index 3d62e30b52a786..5383ebc03a650c 100644 --- a/src/sentry/migrations/0760_remove_appstore_connect_integration_tables.py +++ b/src/sentry/migrations/0760_remove_appstore_connect_integration_tables.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0759_remove_spanattributeextraction_tables"), ] diff --git a/src/sentry/migrations/0776_drop_group_score_in_database.py b/src/sentry/migrations/0776_drop_group_score_in_database.py index 53ed5f75b6f0d2..2a9f36dd7e98f8 100644 --- a/src/sentry/migrations/0776_drop_group_score_in_database.py +++ b/src/sentry/migrations/0776_drop_group_score_in_database.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = True + allow_run_sql = True + dependencies = [ ("sentry", "0775_add_dashboard_permissions_model"), ] diff --git a/src/sentry/migrations/0785_add_new_field_to_dashboard_permissions.py b/src/sentry/migrations/0785_add_new_field_to_dashboard_permissions.py index 32912ed3a81cfc..bae928a544df7d 100644 --- a/src/sentry/migrations/0785_add_new_field_to_dashboard_permissions.py +++ b/src/sentry/migrations/0785_add_new_field_to_dashboard_permissions.py @@ -23,6 +23,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0784_remove_broadcasts_cta_column"), ] diff --git a/src/sentry/migrations/0786_drop_broadcasts_cta_column.py b/src/sentry/migrations/0786_drop_broadcasts_cta_column.py index fd14d73769726a..c8cac50728a022 100644 --- a/src/sentry/migrations/0786_drop_broadcasts_cta_column.py +++ b/src/sentry/migrations/0786_drop_broadcasts_cta_column.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0785_add_new_field_to_dashboard_permissions"), ] diff --git a/src/sentry/migrations/0790_delete_dashboard_perms_col.py b/src/sentry/migrations/0790_delete_dashboard_perms_col.py index 5349d41fd14706..38e17ab6fda1da 100644 --- a/src/sentry/migrations/0790_delete_dashboard_perms_col.py +++ b/src/sentry/migrations/0790_delete_dashboard_perms_col.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0789_add_unique_constraint_to_rollbackorganization"), ] diff --git a/src/sentry/new_migrations/migrations.py b/src/sentry/new_migrations/migrations.py index ecb9968ebf677b..9dc3a5128e2807 100644 --- a/src/sentry/new_migrations/migrations.py +++ b/src/sentry/new_migrations/migrations.py @@ -1,4 +1,5 @@ -from django.db.migrations import Migration +from django.db.migrations import Migration, RunSQL +from django_zero_downtime_migrations.backends.postgres.schema import UnsafeOperationException class CheckedMigration(Migration): @@ -16,7 +17,20 @@ class CheckedMigration(Migration): # the `owners-migrations` team. checked = True + # This determines whether we allow `RunSQL` to be used in migrations. We want to discourage this going forward, + # because it's hard for our framework to determine whether SQL is safe. It can also cause problems with setting + # lock/statement timeouts appropriately. + allow_run_sql = False + def apply(self, project_state, schema_editor, collect_sql=False): if self.checked: schema_editor.safe = True + for op in self.operations: + if not self.allow_run_sql and type(op) is RunSQL: + raise UnsafeOperationException( + "Using RunSQL is unsafe because our migrations safety framework can't detect problems with the " + "migration. If you need to use RunSQL, set `allow_run_sql = True` and get approval from " + "`owners-migrations` to make sure that it's safe." + ) + return super().apply(project_state, schema_editor, collect_sql) diff --git a/src/sentry/remote_subscriptions/migrations/0003_drop_remote_subscription.py b/src/sentry/remote_subscriptions/migrations/0003_drop_remote_subscription.py index 650fd61c8b7e04..32b828597f44fa 100644 --- a/src/sentry/remote_subscriptions/migrations/0003_drop_remote_subscription.py +++ b/src/sentry/remote_subscriptions/migrations/0003_drop_remote_subscription.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("remote_subscriptions", "0002_remove_separate_remote_subscription"), ("uptime", "0003_drop_remote_subscription"), diff --git a/src/sentry/uptime/migrations/0002_remove_separate_remote_subscription.py b/src/sentry/uptime/migrations/0002_remove_separate_remote_subscription.py index bd79fb509bbbc4..cee3dbc032f816 100644 --- a/src/sentry/uptime/migrations/0002_remove_separate_remote_subscription.py +++ b/src/sentry/uptime/migrations/0002_remove_separate_remote_subscription.py @@ -22,6 +22,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("uptime", "0001_uptime_subscriptions"), ("remote_subscriptions", "0001_remote_subscription"), diff --git a/src/sentry/uptime/migrations/0003_drop_remote_subscription.py b/src/sentry/uptime/migrations/0003_drop_remote_subscription.py index 77cf78803a6b1b..baaa9f57d0b69b 100644 --- a/src/sentry/uptime/migrations/0003_drop_remote_subscription.py +++ b/src/sentry/uptime/migrations/0003_drop_remote_subscription.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("uptime", "0002_remove_separate_remote_subscription"), ] diff --git a/src/sentry/uptime/migrations/0004_projectuptimesubscription_mode.py b/src/sentry/uptime/migrations/0004_projectuptimesubscription_mode.py index 0dec267cd7a3bc..7c45752c8c0ea7 100644 --- a/src/sentry/uptime/migrations/0004_projectuptimesubscription_mode.py +++ b/src/sentry/uptime/migrations/0004_projectuptimesubscription_mode.py @@ -22,6 +22,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0731_add_insight_project_flags"), ("uptime", "0003_drop_remote_subscription"), diff --git a/src/sentry/uptime/migrations/0005_uptime_status.py b/src/sentry/uptime/migrations/0005_uptime_status.py index b2e5c67d86a5d1..5402acf8352eb2 100644 --- a/src/sentry/uptime/migrations/0005_uptime_status.py +++ b/src/sentry/uptime/migrations/0005_uptime_status.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("uptime", "0004_projectuptimesubscription_mode"), ] diff --git a/src/sentry/uptime/migrations/0006_projectuptimesubscription_name_owner.py b/src/sentry/uptime/migrations/0006_projectuptimesubscription_name_owner.py index 700265fef0eb70..61a26021ead98c 100644 --- a/src/sentry/uptime/migrations/0006_projectuptimesubscription_name_owner.py +++ b/src/sentry/uptime/migrations/0006_projectuptimesubscription_name_owner.py @@ -23,6 +23,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("sentry", "0742_backfill_alertrule_detection_type"), ("uptime", "0005_uptime_status"), diff --git a/src/sentry/uptime/migrations/0008_uptime_url_suffix.py b/src/sentry/uptime/migrations/0008_uptime_url_suffix.py index f1ea789154cca2..57ffe779e502ed 100644 --- a/src/sentry/uptime/migrations/0008_uptime_url_suffix.py +++ b/src/sentry/uptime/migrations/0008_uptime_url_suffix.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("uptime", "0007_update_detected_subscription_interval"), ] diff --git a/src/sentry/uptime/migrations/0011_remove_uptime_whois_columns_db.py b/src/sentry/uptime/migrations/0011_remove_uptime_whois_columns_db.py index fe4996ed21c1dc..529f7f7731c993 100644 --- a/src/sentry/uptime/migrations/0011_remove_uptime_whois_columns_db.py +++ b/src/sentry/uptime/migrations/0011_remove_uptime_whois_columns_db.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("uptime", "0010_remove_uptime_whois_columns_state"), ] diff --git a/src/sentry/uptime/migrations/0012_uptime_subscription_request_fields.py b/src/sentry/uptime/migrations/0012_uptime_subscription_request_fields.py index 87b20132abb29c..882fdca1fe9154 100644 --- a/src/sentry/uptime/migrations/0012_uptime_subscription_request_fields.py +++ b/src/sentry/uptime/migrations/0012_uptime_subscription_request_fields.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("uptime", "0011_remove_uptime_whois_columns_db"), ] diff --git a/src/sentry/uptime/migrations/0018_add_trace_sampling_field_to_uptime.py b/src/sentry/uptime/migrations/0018_add_trace_sampling_field_to_uptime.py index 84ab364596b37a..d16374639f1e48 100644 --- a/src/sentry/uptime/migrations/0018_add_trace_sampling_field_to_uptime.py +++ b/src/sentry/uptime/migrations/0018_add_trace_sampling_field_to_uptime.py @@ -20,6 +20,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("uptime", "0017_unique_on_timeout"), ] diff --git a/src/sentry/workflow_engine/migrations/0010_detector_state_unique_group.py b/src/sentry/workflow_engine/migrations/0010_detector_state_unique_group.py index 51288a9ed8f74e..8d5a41873bbe77 100644 --- a/src/sentry/workflow_engine/migrations/0010_detector_state_unique_group.py +++ b/src/sentry/workflow_engine/migrations/0010_detector_state_unique_group.py @@ -21,6 +21,8 @@ class Migration(CheckedMigration): is_post_deployment = False + allow_run_sql = True + dependencies = [ ("workflow_engine", "0009_detector_type"), ] diff --git a/tests/sentry/db/postgres/schema/safe_migrations/integration/test_migrations.py b/tests/sentry/db/postgres/schema/safe_migrations/integration/test_migrations.py index dbbf62b2e187cd..80dec14906ed35 100644 --- a/tests/sentry/db/postgres/schema/safe_migrations/integration/test_migrations.py +++ b/tests/sentry/db/postgres/schema/safe_migrations/integration/test_migrations.py @@ -187,6 +187,28 @@ def test(self): self.run_migration() +class RunSqlDisabledTest(BaseSafeMigrationTest): + app = "bad_flow_run_sql_disabled_app" + migrate_from = "0001_initial" + migrate_to = "0001_initial" + + def test(self): + with pytest.raises( + UnsafeOperationException, + match="Using RunSQL is unsafe because our migrations safety framework can't detect problems with the migration.", + ): + self.run_migration() + + +class RunSqlEnabledTest(BaseSafeMigrationTest): + app = "good_flow_run_sql_enabled_app" + migrate_from = "0001_initial" + migrate_to = "0001_initial" + + def test(self): + self.run_migration() + + class DeleteModelCorrectTest(BaseSafeMigrationTest): app = "good_flow_delete_model_state_app" migrate_from = "0001_initial"