mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #34052 -- Made migrate --check don't emit signals and output when up to date.
This commit is contained in:
parent
cff1f888e9
commit
1a7b6909ac
@ -240,23 +240,27 @@ class Command(BaseCommand):
|
||||
self.stdout.write(" No migrations to prune.")
|
||||
|
||||
plan = executor.migration_plan(targets)
|
||||
exit_dry = plan and options["check_unapplied"]
|
||||
|
||||
if options["plan"]:
|
||||
self.stdout.write("Planned operations:", self.style.MIGRATE_LABEL)
|
||||
if not plan:
|
||||
self.stdout.write(" No planned migration operations.")
|
||||
else:
|
||||
for migration, backwards in plan:
|
||||
self.stdout.write(str(migration), self.style.MIGRATE_HEADING)
|
||||
for operation in migration.operations:
|
||||
message, is_error = self.describe_operation(operation, backwards)
|
||||
message, is_error = self.describe_operation(
|
||||
operation, backwards
|
||||
)
|
||||
style = self.style.WARNING if is_error else None
|
||||
self.stdout.write(" " + message, style)
|
||||
if exit_dry:
|
||||
if options["check_unapplied"]:
|
||||
sys.exit(1)
|
||||
return
|
||||
if exit_dry:
|
||||
if options["check_unapplied"]:
|
||||
if plan:
|
||||
sys.exit(1)
|
||||
return
|
||||
if options["prune"]:
|
||||
return
|
||||
|
||||
|
@ -156,3 +156,15 @@ class MigrateSignalTests(TransactionTestCase):
|
||||
],
|
||||
["migrate_signals.Signal"],
|
||||
)
|
||||
# Migrating with an empty plan and --check doesn't emit signals.
|
||||
pre_migrate_receiver = Receiver(signals.pre_migrate)
|
||||
post_migrate_receiver = Receiver(signals.post_migrate)
|
||||
management.call_command(
|
||||
"migrate",
|
||||
database=MIGRATE_DATABASE,
|
||||
verbosity=MIGRATE_VERBOSITY,
|
||||
interactive=MIGRATE_INTERACTIVE,
|
||||
check_unapplied=True,
|
||||
)
|
||||
self.assertEqual(pre_migrate_receiver.call_counter, 0)
|
||||
self.assertEqual(post_migrate_receiver.call_counter, 0)
|
||||
|
@ -355,6 +355,26 @@ class MigrateTests(MigrationTestBase):
|
||||
self.assertTableNotExists("migrations_tribble")
|
||||
self.assertTableNotExists("migrations_book")
|
||||
|
||||
@override_settings(
|
||||
INSTALLED_APPS=[
|
||||
"migrations.migrations_test_apps.migrated_app",
|
||||
]
|
||||
)
|
||||
def test_migrate_check_migrated_app(self):
|
||||
out = io.StringIO()
|
||||
try:
|
||||
call_command("migrate", "migrated_app", verbosity=0)
|
||||
call_command(
|
||||
"migrate",
|
||||
"migrated_app",
|
||||
stdout=out,
|
||||
check_unapplied=True,
|
||||
)
|
||||
self.assertEqual(out.getvalue(), "")
|
||||
finally:
|
||||
# Unmigrate everything.
|
||||
call_command("migrate", "migrated_app", "zero", verbosity=0)
|
||||
|
||||
@override_settings(
|
||||
MIGRATION_MODULES={
|
||||
"migrations": "migrations.test_migrations_plan",
|
||||
|
Loading…
Reference in New Issue
Block a user