diff options
author | David Wobrock <david.wobrock@gmail.com> | 2022-05-04 16:03:09 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-05-17 07:21:36 +0200 |
commit | 97f124f39e363bf518fbe428320bdee63d56f8e0 (patch) | |
tree | c712856f3477d20403d70a074ef564162bc106f1 /tests/migrations | |
parent | a098cde9683a560bfc4b22f9b2581cf8cedc7dab (diff) | |
download | django-97f124f39e363bf518fbe428320bdee63d56f8e0.tar.gz |
Refs #27064 -- Made migrations generate RenameIndex operations when moving indexes from index_together to Meta.indexes.
Diffstat (limited to 'tests/migrations')
-rw-r--r-- | tests/migrations/test_autodetector.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index a28477e590..547e0b32c5 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -2598,6 +2598,79 @@ class AutodetectorTests(TestCase): old_name="book_title_author_idx", ) + def test_rename_index_together_to_index(self): + changes = self.get_changes( + [self.author_empty, self.book_foo_together], + [self.author_empty, self.book_indexes], + ) + self.assertNumberMigrations(changes, "otherapp", 1) + self.assertOperationTypes( + changes, "otherapp", 0, ["RenameIndex", "AlterUniqueTogether"] + ) + self.assertOperationAttributes( + changes, + "otherapp", + 0, + 0, + model_name="book", + new_name="book_title_author_idx", + old_fields=("author", "title"), + ) + self.assertOperationAttributes( + changes, + "otherapp", + 0, + 1, + name="book", + unique_together=set(), + ) + + def test_rename_index_together_to_index_extra_options(self): + # Indexes with extra options don't match indexes in index_together. + book_partial_index = ModelState( + "otherapp", + "Book", + [ + ("id", models.AutoField(primary_key=True)), + ("author", models.ForeignKey("testapp.Author", models.CASCADE)), + ("title", models.CharField(max_length=200)), + ], + { + "indexes": [ + models.Index( + fields=["author", "title"], + condition=models.Q(title__startswith="The"), + name="book_title_author_idx", + ) + ], + }, + ) + changes = self.get_changes( + [self.author_empty, self.book_foo_together], + [self.author_empty, book_partial_index], + ) + self.assertNumberMigrations(changes, "otherapp", 1) + self.assertOperationTypes( + changes, + "otherapp", + 0, + ["AlterUniqueTogether", "AlterIndexTogether", "AddIndex"], + ) + + def test_rename_index_together_to_index_order_fields(self): + # Indexes with reordered fields don't match indexes in index_together. + changes = self.get_changes( + [self.author_empty, self.book_foo_together], + [self.author_empty, self.book_unordered_indexes], + ) + self.assertNumberMigrations(changes, "otherapp", 1) + self.assertOperationTypes( + changes, + "otherapp", + 0, + ["AlterUniqueTogether", "AlterIndexTogether", "AddIndex"], + ) + def test_order_fields_indexes(self): """Test change detection of reordering of fields in indexes.""" changes = self.get_changes( |