diff --git a/src/sentry/runner/commands/upgrade.py b/src/sentry/runner/commands/upgrade.py index a4f550382da291..2babd25cc7cdc3 100644 --- a/src/sentry/runner/commands/upgrade.py +++ b/src/sentry/runner/commands/upgrade.py @@ -3,6 +3,7 @@ from django.db import connections from django.db.utils import ProgrammingError +from sentry.new_migrations.monkey.executor import SentryMigrationExecutor from sentry.runner.decorators import configuration from sentry.signals import post_upgrade from sentry.silo.base import SiloMode @@ -68,6 +69,16 @@ def _upgrade( # Run migrations on all non-read replica connections. # This is used for sentry.io as our production database runs on multiple hosts. if not settings.DATABASES[db_conn].get("REPLICA_OF", False): + # We want the noop case to be quickly skipped. + click.echo(f"Checking for migrations to run for {db_conn}") + conn = connections[db_conn] + executor = SentryMigrationExecutor(conn) + targets = executor.loader.graph.leaf_nodes() + plan = executor.migration_plan(targets) + if not plan: + click.echo(f"No migrations to run for {db_conn}") + continue + click.echo(f"Running migrations for {db_conn}") dj_call_command( "migrate",