Took AlterOrderWithRespectTo into account when optimizing migrations

Thanks Andrew Godwin for the review.
This commit is contained in:
Markus Holtermann 2015-06-13 00:19:05 +02:00
parent 5304494585
commit 5bc412c35a
2 changed files with 19 additions and 3 deletions

View File

@ -21,6 +21,7 @@ class MigrationOptimizer(object):
migrations.AlterModelTable, migrations.AlterModelTable,
migrations.AlterUniqueTogether, migrations.AlterUniqueTogether,
migrations.AlterIndexTogether, migrations.AlterIndexTogether,
migrations.AlterOrderWithRespectTo,
) )
self.field_level_operations = ( self.field_level_operations = (
migrations.AddField, migrations.AddField,
@ -47,6 +48,11 @@ class MigrationOptimizer(object):
migrations.DeleteModel, migrations.DeleteModel,
self.reduce_model_alter_delete, self.reduce_model_alter_delete,
), ),
(
migrations.AlterOrderWithRespectTo,
migrations.DeleteModel,
self.reduce_model_alter_delete,
),
( (
migrations.CreateModel, migrations.CreateModel,
migrations.RenameModel, migrations.RenameModel,

View File

@ -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( self.assertOptimizesTo(
[ [
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]), migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.AlterModelTable("Foo", "woohoo"), migrations.AlterModelTable("Foo", "woohoo"),
migrations.AlterUniqueTogether("Foo", [["a", "b"]]), alter_foo,
migrations.DeleteModel("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): def test_optimize_through_create(self):
""" """
We should be able to optimize away create/delete through a create or delete We should be able to optimize away create/delete through a create or delete