From 5bc412c35a4db9ac064304f9c79d34a8afb44c15 Mon Sep 17 00:00:00 2001 From: Markus Holtermann Date: Sat, 13 Jun 2015 00:19:05 +0200 Subject: [PATCH] Took AlterOrderWithRespectTo into account when optimizing migrations Thanks Andrew Godwin for the review. --- django/db/migrations/optimizer.py | 6 ++++++ tests/migrations/test_optimizer.py | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/django/db/migrations/optimizer.py b/django/db/migrations/optimizer.py index 5bb97b5fe4..caf0798b2e 100644 --- a/django/db/migrations/optimizer.py +++ b/django/db/migrations/optimizer.py @@ -21,6 +21,7 @@ class MigrationOptimizer(object): migrations.AlterModelTable, migrations.AlterUniqueTogether, migrations.AlterIndexTogether, + migrations.AlterOrderWithRespectTo, ) self.field_level_operations = ( migrations.AddField, @@ -47,6 +48,11 @@ class MigrationOptimizer(object): migrations.DeleteModel, self.reduce_model_alter_delete, ), + ( + migrations.AlterOrderWithRespectTo, + migrations.DeleteModel, + self.reduce_model_alter_delete, + ), ( migrations.CreateModel, migrations.RenameModel, diff --git a/tests/migrations/test_optimizer.py b/tests/migrations/test_optimizer.py index e599baac83..b22905b033 100644 --- a/tests/migrations/test_optimizer.py +++ b/tests/migrations/test_optimizer.py @@ -93,20 +93,30 @@ class OptimizerTests(SimpleTestCase): ], ) - def test_create_alter_delete_model(self): + def _test_create_alter_foo_delete_model(self, alter_foo): """ - CreateModel, AlterModelTable, AlterUniqueTogether, and DeleteModel should collapse into nothing. + CreateModel, AlterModelTable, AlterUniqueTogether/AlterIndexTogether/ + AlterOrderWithRespectTo, and DeleteModel should collapse into nothing. """ self.assertOptimizesTo( [ migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), migrations.AlterModelTable("Foo", "woohoo"), - migrations.AlterUniqueTogether("Foo", [["a", "b"]]), + alter_foo, migrations.DeleteModel("Foo"), ], [], ) + def test_create_alter_unique_delete_model(self): + self._test_create_alter_foo_delete_model(migrations.AlterUniqueTogether("Foo", [["a", "b"]])) + + def test_create_alter_index_delete_model(self): + self._test_create_alter_foo_delete_model(migrations.AlterIndexTogether("Foo", [["a", "b"]])) + + def test_create_alter_owrt_delete_model(self): + self._test_create_alter_foo_delete_model(migrations.AlterOrderWithRespectTo("Foo", "a")) + def test_optimize_through_create(self): """ We should be able to optimize away create/delete through a create or delete