|
| 1 | +# Generated by Django 2.2.28 on 2023-01-31 20:37 |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | + |
| 5 | +from sentry.new_migrations.migrations import CheckedMigration |
| 6 | + |
| 7 | + |
| 8 | +class Migration(CheckedMigration): |
| 9 | + # This flag is used to mark that a migration shouldn't be automatically run in production. For |
| 10 | + # the most part, this should only be used for operations where it's safe to run the migration |
| 11 | + # after your code has deployed. So this should not be used for most operations that alter the |
| 12 | + # schema of a table. |
| 13 | + # Here are some things that make sense to mark as dangerous: |
| 14 | + # - Large data migrations. Typically we want these to be run manually by ops so that they can |
| 15 | + # be monitored and not block the deploy for a long period of time while they run. |
| 16 | + # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to |
| 17 | + # have ops run this and not block the deploy. Note that while adding an index is a schema |
| 18 | + # change, it's completely safe to run the operation after the code has deployed. |
| 19 | + is_dangerous = True |
| 20 | + |
| 21 | + dependencies = [ |
| 22 | + ("sentry", "0417_backfill_groupedmessage_substatus"), |
| 23 | + ] |
| 24 | + |
| 25 | + operations = ( |
| 26 | + [ |
| 27 | + migrations.RunSQL( |
| 28 | + sql=line, |
| 29 | + reverse_sql="", |
| 30 | + hints={"tables": ["sentry_actor"]}, |
| 31 | + ) |
| 32 | + for line in """ |
| 33 | +ALTER TABLE "sentry_actor" DROP CONSTRAINT IF EXISTS "sentry_actor_team_id_6ca8eba5_fk_sentry_team_id"; |
| 34 | +ALTER TABLE "sentry_actor" DROP CONSTRAINT IF EXISTS "sentry_actor_team_id_6ca8eba5_uniq"; |
| 35 | +DROP INDEX CONCURRENTLY IF EXISTS "sentry_actor_team_id_6ca8eba5"; |
| 36 | +DROP INDEX CONCURRENTLY IF EXISTS "sentry_actor_team_id_6ca8eba5_uniq"; |
| 37 | +
|
| 38 | +CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "sentry_actor_team_id_6ca8eba5_uniq" ON "sentry_actor" ("team_id"); |
| 39 | +ALTER TABLE "sentry_actor" ADD CONSTRAINT "sentry_actor_team_id_6ca8eba5_fk_sentry_team_id" FOREIGN KEY ("team_id") REFERENCES "sentry_team" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID; |
| 40 | +ALTER TABLE "sentry_actor" VALIDATE CONSTRAINT "sentry_actor_team_id_6ca8eba5_fk_sentry_team_id"; |
| 41 | +
|
| 42 | +ALTER TABLE "sentry_actor" DROP CONSTRAINT IF EXISTS "sentry_actor_user_id_c832ff63_uniq"; |
| 43 | +DROP INDEX CONCURRENTLY IF EXISTS "sentry_actor_user_id_c832ff63"; |
| 44 | +DROP INDEX CONCURRENTLY IF EXISTS "sentry_actor_user_id_c832ff63_uniq"; |
| 45 | +CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "sentry_actor_user_id_c832ff63_uniq" ON "sentry_actor" ("user_id"); |
| 46 | + """.splitlines() |
| 47 | + if line.strip() |
| 48 | + ] |
| 49 | + + [ |
| 50 | + migrations.RunSQL( |
| 51 | + sql="SELECT 1", |
| 52 | + reverse_sql=""" |
| 53 | +ALTER TABLE "sentry_actor" ADD CONSTRAINT "sentry_actor_team_id_6ca8eba5_uniq" UNIQUE USING INDEX "sentry_actor_team_id_6ca8eba5_uniq"; |
| 54 | + """, |
| 55 | + hints={"tables": ["sentry_actor"]}, |
| 56 | + ), |
| 57 | + migrations.RunSQL( |
| 58 | + sql="SELECT 1", |
| 59 | + reverse_sql=""" |
| 60 | +ALTER TABLE "sentry_actor" ADD CONSTRAINT "sentry_actor_user_id_c832ff63_uniq" UNIQUE USING INDEX "sentry_actor_user_id_c832ff63_uniq"; |
| 61 | + """, |
| 62 | + hints={"tables": ["sentry_actor"]}, |
| 63 | + ), |
| 64 | + ] |
| 65 | + ) |
0 commit comments