Loading django/core/management/commands/squashmigrations.py +22 −15 Original line number Diff line number Diff line Loading @@ -26,7 +26,9 @@ class Command(BaseCommand): self.verbosity = options.get('verbosity') self.interactive = options.get('interactive') app_label, migration_name = options['app_label'], options['migration_name'] app_label = options['app_label'] migration_name = options['migration_name'] no_optimize = options['no_optimize'] # Load the current graph state, check the app and migration they asked for exists executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) Loading Loading @@ -95,6 +97,11 @@ class Command(BaseCommand): elif dependency[0] != smigration.app_label: dependencies.add(dependency) if no_optimize: if self.verbosity > 0: self.stdout.write(self.style.MIGRATE_HEADING("(Skipping optimization.)")) new_operations = operations else: if self.verbosity > 0: self.stdout.write(self.style.MIGRATE_HEADING("Optimizing...")) Loading docs/releases/1.7.2.txt +3 −0 Original line number Diff line number Diff line Loading @@ -62,3 +62,6 @@ Bugfixes * Fixed a migration crash when a field is renamed that is part of an ``index_together`` (:ticket:`23859`). * Fixed :djadmin:`squashmigrations` to respect the ``--no-optimize`` parameter (:ticket:`23799`). tests/migrations/test_commands.py +39 −0 Original line number Diff line number Diff line Loading @@ -543,3 +543,42 @@ class MakeMigrationsTests(MigrationTestBase): content = cmd("0002", migration_name_0002, "--empty") self.assertIn("dependencies=[\n('migrations','0001_%s'),\n]" % migration_name_0001, content) self.assertIn("operations=[\n]", content) class SquashMigrationsTest(MigrationTestBase): """ Tests running the squashmigrations command. """ path = "migrations/test_migrations/0001_squashed_0002_second.py" def tearDown(self): if os.path.exists(self.path): os.remove(self.path) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) def test_squashmigrations_squashes(self): """ Tests that squashmigrations squashes migrations. """ call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=0) self.assertTrue(os.path.exists(self.path)) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) def test_squashmigrations_optimizes(self): """ Tests that squashmigrations optimizes operations. """ out = six.StringIO() call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, stdout=out) self.assertIn("Optimized from 7 operations to 5 operations.", out.getvalue()) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) def test_ticket_23799_squashmigrations_no_optimize(self): """ Makes sure that squashmigrations --no-optimize really doesn't optimize operations. """ out = six.StringIO() call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, no_optimize=True, stdout=out) self.assertIn("Skipping optimization", out.getvalue()) Loading
django/core/management/commands/squashmigrations.py +22 −15 Original line number Diff line number Diff line Loading @@ -26,7 +26,9 @@ class Command(BaseCommand): self.verbosity = options.get('verbosity') self.interactive = options.get('interactive') app_label, migration_name = options['app_label'], options['migration_name'] app_label = options['app_label'] migration_name = options['migration_name'] no_optimize = options['no_optimize'] # Load the current graph state, check the app and migration they asked for exists executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) Loading Loading @@ -95,6 +97,11 @@ class Command(BaseCommand): elif dependency[0] != smigration.app_label: dependencies.add(dependency) if no_optimize: if self.verbosity > 0: self.stdout.write(self.style.MIGRATE_HEADING("(Skipping optimization.)")) new_operations = operations else: if self.verbosity > 0: self.stdout.write(self.style.MIGRATE_HEADING("Optimizing...")) Loading
docs/releases/1.7.2.txt +3 −0 Original line number Diff line number Diff line Loading @@ -62,3 +62,6 @@ Bugfixes * Fixed a migration crash when a field is renamed that is part of an ``index_together`` (:ticket:`23859`). * Fixed :djadmin:`squashmigrations` to respect the ``--no-optimize`` parameter (:ticket:`23799`).
tests/migrations/test_commands.py +39 −0 Original line number Diff line number Diff line Loading @@ -543,3 +543,42 @@ class MakeMigrationsTests(MigrationTestBase): content = cmd("0002", migration_name_0002, "--empty") self.assertIn("dependencies=[\n('migrations','0001_%s'),\n]" % migration_name_0001, content) self.assertIn("operations=[\n]", content) class SquashMigrationsTest(MigrationTestBase): """ Tests running the squashmigrations command. """ path = "migrations/test_migrations/0001_squashed_0002_second.py" def tearDown(self): if os.path.exists(self.path): os.remove(self.path) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) def test_squashmigrations_squashes(self): """ Tests that squashmigrations squashes migrations. """ call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=0) self.assertTrue(os.path.exists(self.path)) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) def test_squashmigrations_optimizes(self): """ Tests that squashmigrations optimizes operations. """ out = six.StringIO() call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, stdout=out) self.assertIn("Optimized from 7 operations to 5 operations.", out.getvalue()) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) def test_ticket_23799_squashmigrations_no_optimize(self): """ Makes sure that squashmigrations --no-optimize really doesn't optimize operations. """ out = six.StringIO() call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, no_optimize=True, stdout=out) self.assertIn("Skipping optimization", out.getvalue())