summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormlavin <markdlavin@gmail.com>2015-08-06 21:12:00 -0400
committerTim Graham <timograham@gmail.com>2015-08-07 17:59:18 -0400
commit69db1c745506bf63026def25d6854755179feaa8 (patch)
tree32cbd88189188ad00b9a911051d7c5e9c1f5d03f
parenta7b7f27c05244d69a11545261eb3bbd73791b3d2 (diff)
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.
-rw-r--r--django/core/management/commands/migrate.py1
-rw-r--r--docs/releases/1.8.4.txt3
-rw-r--r--tests/migrations/test_commands.py46
3 files changed, 50 insertions, 0 deletions
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py
index fe26a0fbf6..2f048240b5 100644
--- a/django/core/management/commands/migrate.py
+++ b/django/core/management/commands/migrate.py
@@ -171,6 +171,7 @@ class Command(BaseCommand):
if self.verbosity >= 1:
self.stdout.write(self.style.MIGRATE_HEADING("Running migrations:"))
if not plan:
+ executor.check_replacements()
if self.verbosity >= 1:
self.stdout.write(" No migrations to apply.")
# If there's changes that aren't in migrations yet, tell them how to fix it.
diff --git a/docs/releases/1.8.4.txt b/docs/releases/1.8.4.txt
index 070397e885..77ca647ff0 100644
--- a/docs/releases/1.8.4.txt
+++ b/docs/releases/1.8.4.txt
@@ -24,3 +24,6 @@ Bugfixes
* Fixed ``has_changed()`` method in ``contrib.postgres.forms.HStoreField``
(:ticket:`25215`, :ticket:`25233`).
+
+* Fixed the recording of squashed migrations when running the ``migrate``
+ command (:ticket:`25231`).
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index f50a1820ae..41860e64dd 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -8,6 +8,7 @@ import os
from django.apps import apps
from django.core.management import CommandError, call_command
from django.db import DatabaseError, connection, models
+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
@@ -413,6 +414,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):
"""