Skip to content

Commit

Permalink
feat(migrations): Prevent new migrations from using RunSQL (getsent…
Browse files Browse the repository at this point in the history
…ry#81003)

This adds in `allow_run_sql` to our `CheckedMigration` baseclass. We
want to prevent the use of `RunSQL` in most cases going forward, since
our migration safety framework doesn't know how to parse sql to ensure
safety.

Our main uses for this in the past were:
- Adding new columns with a default. We now can do this within the
framework by using `db_default` instead of `default`.
- Deleting columns/tables. Since we have to remove from state, deploy,
then delete we have to use raw sql to remove them from Postgres. I'll
follow this up with a pr to provide ways to handle these deletions
within our framework.
  • Loading branch information
wedamija authored Nov 22, 2024
1 parent c70f656 commit 64c5f94
Show file tree
Hide file tree
Showing 86 changed files with 234 additions and 16 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -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;")]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.db import models


class TestTable(models.Model):
field = models.IntegerField(default=0, null=False)
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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),
]
Original file line number Diff line number Diff line change
@@ -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),
]
Empty file.
Original file line number Diff line number Diff line change
@@ -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;")]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.db import models


class TestTable(models.Model):
field = models.IntegerField(default=0, null=False)
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0490_add_is_test_to_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0505_debugfile_date_accessed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0526_pr_comment_type_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0570_repository_add_languages_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0590_add_metadata_to_sentry_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0607_drop_externalactor_actorid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0624_add_is_muted_monitorenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0651_enable_activated_alert_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/migrations/0658_projectkey_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down
Loading

0 comments on commit 64c5f94

Please sign in to comment.