Fixed #24828 -- Allowed migration optimization across AlterFooTogether

The idea behind this change is, that AlterUniqueTogether,
AlterIndexTogether and AlterOrderWithRespectTo can always be moved after
an Add/Alter/Rename/RemoveField operation if they don't refer to the
respective field and are not empty sets / None.

Combined with the optimizations of duplicate AlterUniqueTogether,
AlterIndexTogether, and AlterOrderWithRespectTo operations from
128caa1e16, these operations are optimized
in a later round of the optimizer.

Thanks Tim Graham for the review.
This commit is contained in:
Markus Holtermann 2015-06-13 00:21:07 +02:00
parent fb1ba4d63e
commit e470f311d6
5 changed files with 208 additions and 4 deletions

View file

@ -1149,9 +1149,10 @@ class AutodetectorTests(TestCase):
changes = autodetector._detect_changes()
# Right number/type of migrations?
self.assertNumberMigrations(changes, "otherapp", 1)
self.assertOperationTypes(changes, "otherapp", 0, ["AlterUniqueTogether", "AlterIndexTogether", "RemoveField"])
self.assertOperationAttributes(changes, "otherapp", 0, 0, name="book", unique_together={("author", "title")})
self.assertOperationAttributes(changes, "otherapp", 0, 1, name="book", index_together={("author", "title")})
self.assertOperationTypes(changes, "otherapp", 0, ["RemoveField", "AlterUniqueTogether", "AlterIndexTogether"])
self.assertOperationAttributes(changes, "otherapp", 0, 0, model_name="book", name="newfield")
self.assertOperationAttributes(changes, "otherapp", 0, 1, name="book", unique_together={("author", "title")})
self.assertOperationAttributes(changes, "otherapp", 0, 2, name="book", index_together={("author", "title")})
def test_rename_field_and_foo_together(self):
"""