diff options
author | David Wobrock <david.wobrock@gmail.com> | 2022-05-03 14:43:06 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-05-16 17:46:24 +0200 |
commit | c6cec3c2d287b5d2bd36d9c3002712ae89b5ab17 (patch) | |
tree | fb370652afdf7d742e39447324ed22f38e87eb58 /tests/migrations | |
parent | 11310e9abbdd784aea4ba50451144fc9c239f71f (diff) | |
download | django-c6cec3c2d287b5d2bd36d9c3002712ae89b5ab17.tar.gz |
Refs #27064 -- Made migrations generate RenameIndex operations when renaming Meta.indexes.
Diffstat (limited to 'tests/migrations')
-rw-r--r-- | tests/migrations/test_autodetector.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 0d7a44e42d..a28477e590 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -2565,6 +2565,39 @@ class AutodetectorTests(TestCase): changes, "otherapp", 0, 0, model_name="book", name="book_title_author_idx" ) + def test_rename_indexes(self): + book_renamed_indexes = 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"], name="renamed_book_title_author_idx" + ) + ], + }, + ) + changes = self.get_changes( + [self.author_empty, self.book_indexes], + [self.author_empty, book_renamed_indexes], + ) + self.assertNumberMigrations(changes, "otherapp", 1) + self.assertOperationTypes(changes, "otherapp", 0, ["RenameIndex"]) + self.assertOperationAttributes( + changes, + "otherapp", + 0, + 0, + model_name="book", + new_name="renamed_book_title_author_idx", + old_name="book_title_author_idx", + ) + def test_order_fields_indexes(self): """Test change detection of reordering of fields in indexes.""" changes = self.get_changes( |