mirror of
https://github.com/django/django.git
synced 2025-01-03 15:06:09 +00:00
Fixed #34528 -- Reduced Add/RemoveIndex operations when optimizing migrations.
This commit is contained in:
parent
0b0998dc15
commit
191f6a9a45
@ -861,6 +861,11 @@ class AddIndex(IndexOperation):
|
||||
def migration_name_fragment(self):
|
||||
return "%s_%s" % (self.model_name_lower, self.index.name.lower())
|
||||
|
||||
def reduce(self, operation, app_label):
|
||||
if isinstance(operation, RemoveIndex) and self.index.name == operation.name:
|
||||
return []
|
||||
return super().reduce(operation, app_label)
|
||||
|
||||
|
||||
class RemoveIndex(IndexOperation):
|
||||
"""Remove an index from a model."""
|
||||
|
@ -1158,3 +1158,17 @@ class OptimizerTests(SimpleTestCase):
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
def test_add_remove_index(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.AddIndex(
|
||||
"Pony",
|
||||
models.Index(
|
||||
fields=["weight", "pink"], name="idx_pony_weight_pink"
|
||||
),
|
||||
),
|
||||
migrations.RemoveIndex("Pony", "idx_pony_weight_pink"),
|
||||
],
|
||||
[],
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user