diff --git a/migrations_lockfile.txt b/migrations_lockfile.txt index 856cd6648d5967..bcb627a6cd45e4 100644 --- a/migrations_lockfile.txt +++ b/migrations_lockfile.txt @@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi will then be regenerated, and you should be able to merge without conflicts. nodestore: 0002_nodestore_no_dictfield -sentry: 0417_backfill_groupedmessage_substatus +sentry: 0418_add_actor_constraints social_auth: 0001_initial diff --git a/src/sentry/migrations/0418_add_actor_constraints.py b/src/sentry/migrations/0418_add_actor_constraints.py new file mode 100644 index 00000000000000..82ccdfabfe794f --- /dev/null +++ b/src/sentry/migrations/0418_add_actor_constraints.py @@ -0,0 +1,65 @@ +# Generated by Django 2.2.28 on 2023-01-31 20:37 + +from django.db import migrations + +from sentry.new_migrations.migrations import CheckedMigration + + +class Migration(CheckedMigration): + # This flag is used to mark that a migration shouldn't be automatically run in production. For + # the most part, this should only be used for operations where it's safe to run the migration + # after your code has deployed. So this should not be used for most operations that alter the + # schema of a table. + # Here are some things that make sense to mark as dangerous: + # - Large data migrations. Typically we want these to be run manually by ops so that they can + # be monitored and not block the deploy for a long period of time while they run. + # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to + # have ops run this and not block the deploy. Note that while adding an index is a schema + # change, it's completely safe to run the operation after the code has deployed. + is_dangerous = True + + dependencies = [ + ("sentry", "0417_backfill_groupedmessage_substatus"), + ] + + operations = ( + [ + migrations.RunSQL( + sql=line, + reverse_sql="", + hints={"tables": ["sentry_actor"]}, + ) + for line in """ +ALTER TABLE "sentry_actor" DROP CONSTRAINT IF EXISTS "sentry_actor_team_id_6ca8eba5_fk_sentry_team_id"; +ALTER TABLE "sentry_actor" DROP CONSTRAINT IF EXISTS "sentry_actor_team_id_6ca8eba5_uniq"; +DROP INDEX CONCURRENTLY IF EXISTS "sentry_actor_team_id_6ca8eba5"; +DROP INDEX CONCURRENTLY IF EXISTS "sentry_actor_team_id_6ca8eba5_uniq"; + +CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "sentry_actor_team_id_6ca8eba5_uniq" ON "sentry_actor" ("team_id"); +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; +ALTER TABLE "sentry_actor" VALIDATE CONSTRAINT "sentry_actor_team_id_6ca8eba5_fk_sentry_team_id"; + +ALTER TABLE "sentry_actor" DROP CONSTRAINT IF EXISTS "sentry_actor_user_id_c832ff63_uniq"; +DROP INDEX CONCURRENTLY IF EXISTS "sentry_actor_user_id_c832ff63"; +DROP INDEX CONCURRENTLY IF EXISTS "sentry_actor_user_id_c832ff63_uniq"; +CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "sentry_actor_user_id_c832ff63_uniq" ON "sentry_actor" ("user_id"); + """.splitlines() + if line.strip() + ] + + [ + migrations.RunSQL( + sql="SELECT 1", + reverse_sql=""" +ALTER TABLE "sentry_actor" ADD CONSTRAINT "sentry_actor_team_id_6ca8eba5_uniq" UNIQUE USING INDEX "sentry_actor_team_id_6ca8eba5_uniq"; + """, + hints={"tables": ["sentry_actor"]}, + ), + migrations.RunSQL( + sql="SELECT 1", + reverse_sql=""" +ALTER TABLE "sentry_actor" ADD CONSTRAINT "sentry_actor_user_id_c832ff63_uniq" UNIQUE USING INDEX "sentry_actor_user_id_c832ff63_uniq"; + """, + hints={"tables": ["sentry_actor"]}, + ), + ] + ) diff --git a/src/sentry/models/integrations/pagerduty_service.py b/src/sentry/models/integrations/pagerduty_service.py index 3b98346142286d..0cc7d747f8a5d7 100644 --- a/src/sentry/models/integrations/pagerduty_service.py +++ b/src/sentry/models/integrations/pagerduty_service.py @@ -13,7 +13,7 @@ @region_silo_only_model -class PagerDutyService(DefaultFieldsModel, OrganizationIntegrityBackfillMixin): +class PagerDutyService(OrganizationIntegrityBackfillMixin, DefaultFieldsModel): __include_in_export__ = False organization_integration = FlexibleForeignKey("sentry.OrganizationIntegration") diff --git a/src/sentry/models/integrations/repository_project_path_config.py b/src/sentry/models/integrations/repository_project_path_config.py index ff80964698ec49..be451fbb862607 100644 --- a/src/sentry/models/integrations/repository_project_path_config.py +++ b/src/sentry/models/integrations/repository_project_path_config.py @@ -13,7 +13,7 @@ @region_silo_only_model -class RepositoryProjectPathConfig(DefaultFieldsModel, OrganizationIntegrityBackfillMixin): +class RepositoryProjectPathConfig(OrganizationIntegrityBackfillMixin, DefaultFieldsModel): __include_in_export__ = False repository = FlexibleForeignKey("sentry.Repository")