mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #35122 -- Made migrate --prune option respect --app_label.
This commit is contained in:
committed by
Mariusz Felisiak
parent
222bf2932b
commit
cf107fe255
@@ -1427,6 +1427,53 @@ class MigrateTests(MigrationTestBase):
|
||||
with self.assertRaisesMessage(CommandError, msg):
|
||||
call_command("migrate", prune=True)
|
||||
|
||||
@override_settings(
|
||||
MIGRATION_MODULES={
|
||||
"migrations": "migrations.test_migrations_squashed_no_replaces",
|
||||
"migrations2": "migrations2.test_migrations_2_squashed_with_replaces",
|
||||
},
|
||||
INSTALLED_APPS=["migrations", "migrations2"],
|
||||
)
|
||||
def test_prune_respect_app_label(self):
|
||||
recorder = MigrationRecorder(connection)
|
||||
recorder.record_applied("migrations", "0001_initial")
|
||||
recorder.record_applied("migrations", "0002_second")
|
||||
recorder.record_applied("migrations", "0001_squashed_0002")
|
||||
# Second app has squashed migrations with replaces.
|
||||
recorder.record_applied("migrations2", "0001_initial")
|
||||
recorder.record_applied("migrations2", "0002_second")
|
||||
recorder.record_applied("migrations2", "0001_squashed_0002")
|
||||
out = io.StringIO()
|
||||
try:
|
||||
call_command("migrate", "migrations", prune=True, stdout=out, no_color=True)
|
||||
self.assertEqual(
|
||||
out.getvalue(),
|
||||
"Pruning migrations:\n"
|
||||
" Pruning migrations.0001_initial OK\n"
|
||||
" Pruning migrations.0002_second OK\n",
|
||||
)
|
||||
applied_migrations = [
|
||||
migration
|
||||
for migration in recorder.applied_migrations()
|
||||
if migration[0] in ["migrations", "migrations2"]
|
||||
]
|
||||
self.assertEqual(
|
||||
applied_migrations,
|
||||
[
|
||||
("migrations", "0001_squashed_0002"),
|
||||
("migrations2", "0001_initial"),
|
||||
("migrations2", "0002_second"),
|
||||
("migrations2", "0001_squashed_0002"),
|
||||
],
|
||||
)
|
||||
finally:
|
||||
recorder.record_unapplied("migrations", "0001_initial")
|
||||
recorder.record_unapplied("migrations", "0001_second")
|
||||
recorder.record_unapplied("migrations", "0001_squashed_0002")
|
||||
recorder.record_unapplied("migrations2", "0001_initial")
|
||||
recorder.record_unapplied("migrations2", "0002_second")
|
||||
recorder.record_unapplied("migrations2", "0001_squashed_0002")
|
||||
|
||||
|
||||
class MakeMigrationsTests(MigrationTestBase):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user