summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authormlavin <markdlavin@gmail.com>2015-08-06 21:12:00 -0400
committerTim Graham <timograham@gmail.com>2015-08-07 18:16:37 -0400
commitac46eb7e8379e451d0acc1ace666fabd56d016ce (patch)
treeb12253865ce8d1a2d02f2f70e49101d405f96e4e /tests
parentad2ac53054f1deea6818d05220db73f6c09c1702 (diff)
[1.8.x] Fixed #25231 -- Added recording of squashed migrations in the migrate command.
Ensured squashed migrations are recorded as applied when the migrate command is run and all of the original migrations have been previously applied. Backport of 69db1c745506bf63026def25d6854755179feaa8 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_commands.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 02a533aacd..3b05c92ed6 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -10,6 +10,7 @@ from django.apps import apps
from django.core.management import CommandError, call_command
from django.db import DatabaseError, connection, models
from django.db.migrations import questioner
+from django.db.migrations.recorder import MigrationRecorder
from django.test import ignore_warnings, mock, override_settings
from django.utils import six
from django.utils.deprecation import RemovedInDjango110Warning
@@ -338,6 +339,51 @@ class MigrateTests(MigrationTestBase):
"""
call_command("migrate", "migrated_unapplied_app", stdout=six.StringIO())
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"})
+ def test_migrate_record_replaced(self):
+ """
+ Running a single squashed migration should record all of the original
+ replaced migrations as run.
+ """
+ recorder = MigrationRecorder(connection)
+ out = six.StringIO()
+ call_command("migrate", "migrations", verbosity=0)
+ call_command("showmigrations", "migrations", stdout=out, no_color=True)
+ self.assertEqual(
+ 'migrations\n'
+ ' [x] 0001_squashed_0002 (2 squashed migrations)\n',
+ out.getvalue().lower()
+ )
+ applied_migrations = recorder.applied_migrations()
+ self.assertIn(("migrations", "0001_initial"), applied_migrations)
+ self.assertIn(("migrations", "0002_second"), applied_migrations)
+ self.assertIn(("migrations", "0001_squashed_0002"), applied_migrations)
+ # Rollback changes
+ call_command("migrate", "migrations", "zero", verbosity=0)
+
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"})
+ def test_migrate_record_squashed(self):
+ """
+ Running migrate for a squashed migration should record as run
+ if all of the replaced migrations have been run (#25231).
+ """
+ recorder = MigrationRecorder(connection)
+ recorder.record_applied("migrations", "0001_initial")
+ recorder.record_applied("migrations", "0002_second")
+ out = six.StringIO()
+ call_command("migrate", "migrations", verbosity=0)
+ call_command("showmigrations", "migrations", stdout=out, no_color=True)
+ self.assertEqual(
+ 'migrations\n'
+ ' [x] 0001_squashed_0002 (2 squashed migrations)\n',
+ out.getvalue().lower()
+ )
+ self.assertIn(
+ ("migrations", "0001_squashed_0002"),
+ recorder.applied_migrations()
+ )
+ # No changes were actually applied so there is nothing to rollback
+
class MakeMigrationsTests(MigrationTestBase):
"""