Skip to content

chore(migrations): Switch all uses of RunSQL over to SafeRunSQL, and stop relying on allow_run_sql #90453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import bitfield.models
import sentry.db.models.fields.array
from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -20,16 +21,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "hybridcloud_apikeyreplica" ADD COLUMN "scopes" BIGINT NOT NULL DEFAULT 0;
ALTER TABLE "hybridcloud_apikeyreplica" ADD COLUMN "scope_list" TEXT NULL;
Expand Down
150 changes: 83 additions & 67 deletions src/sentry/migrations/0001_squashed_0484_break_org_member_user_fk.py

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/sentry/migrations/0490_add_is_test_to_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -18,16 +19,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "sentry_organization" ADD COLUMN "is_test" BOOLEAN NOT NULL DEFAULT FALSE;
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -18,14 +19,12 @@ 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"),
]

operations = [
migrations.RunSQL(
SafeRunSQL(
sql="""
ALTER TABLE "sentry_organizationmembermapping" DROP CONSTRAINT "sentry_organizationmembe_organization_id_email_66a560fc_uniq";
ALTER TABLE "sentry_organizationmembermapping" DROP CONSTRAINT "sentry_organizationmembe_organization_id_user_id_feb6bdf0_uniq";
Expand Down
5 changes: 2 additions & 3 deletions src/sentry/migrations/0505_debugfile_date_accessed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -19,8 +20,6 @@ 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 All @@ -36,7 +35,7 @@ class Migration(CheckedMigration):
# Also according to <https://www.postgresql.org/docs/current/xfunc-volatility.html>:
# > Another important example is that the current_timestamp family of functions qualify as STABLE,
# > since their values do not change within a transaction.
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "sentry_projectdsymfile" ADD COLUMN "date_accessed" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP;
""",
Expand Down
5 changes: 2 additions & 3 deletions src/sentry/migrations/0526_pr_comment_type_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sentry.db.models.fields.bounded
import sentry.db.models.fields.foreignkey
from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -21,16 +22,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "sentry_pullrequest_comment" ADD COLUMN "comment_type" integer NOT NULL DEFAULT 0;
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -19,16 +20,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
sql="""
ALTER TABLE "sentry_controloutbox" ADD COLUMN "date_added" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
""",
Expand All @@ -37,7 +36,7 @@ class Migration(CheckedMigration):
""",
hints={"tables": ["sentry_controloutbox"]},
),
migrations.RunSQL(
SafeRunSQL(
sql="""
ALTER TABLE "sentry_regionoutbox" ADD COLUMN "date_added" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import migrations

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -18,8 +19,6 @@ 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 All @@ -43,7 +42,7 @@ class Migration(CheckedMigration):
),
],
database_operations=[
migrations.RunSQL(
SafeRunSQL(
reverse_sql="""
ALTER TABLE sentry_groupsubscription ADD COLUMN team_id BIGINT NULL;
ALTER TABLE sentry_groupsubscription ADD CONSTRAINT "subscription_team_or_user_check" CHECK (team_id IS NOT NULL AND user_id IS NULL OR team_id IS NULL AND user_id IS NOT NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -19,16 +20,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "sentry_authidentityreplica" ADD COLUMN IF NOT EXISTS "last_verified" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW();
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -18,16 +19,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "auth_user" ADD COLUMN "is_unclaimed" boolean NOT NULL DEFAULT FALSE;
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import sentry.db.models.fields.foreignkey
from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -20,8 +21,6 @@ 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 All @@ -45,7 +44,7 @@ class Migration(CheckedMigration):
),
],
database_operations=[
migrations.RunSQL(
SafeRunSQL(
reverse_sql="""
ALTER TABLE "sentry_groupsubscription" ALTER COLUMN "user_id" SET NOT NULL;
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -18,16 +19,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "sentry_organizationmapping" ADD COLUMN "require_2fa" boolean NOT NULL DEFAULT FALSE;
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import migrations

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -18,16 +19,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "sentry_commitfilechange" DROP COLUMN "language";
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sentry.db.models.fields.array
from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -19,16 +20,14 @@ 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"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "sentry_repository" ADD COLUMN "languages" TEXT[] NULL;
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -18,8 +19,6 @@ 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 All @@ -37,7 +36,7 @@ class Migration(CheckedMigration):
operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
SafeRunSQL(
f"""
ALTER TABLE "sentry_organizationmapping" ADD COLUMN "{column}" BOOLEAN NOT NULL DEFAULT false;
""",
Expand Down
5 changes: 2 additions & 3 deletions src/sentry/migrations/0590_add_metadata_to_sentry_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sentry.db.models.fields.jsonfield
from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.special import SafeRunSQL


class Migration(CheckedMigration):
Expand All @@ -19,8 +20,6 @@ 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 All @@ -35,7 +34,7 @@ class Migration(CheckedMigration):
),
],
database_operations=[
migrations.RunSQL(
SafeRunSQL(
"""
ALTER TABLE "sentry_sentryapp" ADD COLUMN "metadata" json NOT NULL DEFAULT '{}';
""",
Expand Down
Loading
Loading