summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAkash Kumar Sen <Akash-Kumar-Sen@users.noreply.github.com>2023-05-08 23:24:46 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-05-09 12:45:09 +0200
commit92f0017133c2d31fbd527bab7b08d4d49a582143 (patch)
tree8c336ea23ba73f6f899e85e15e82d9f37ad7b97d /django
parent59262c294d26d2aa9346284519545c0f988bf353 (diff)
downloaddjango-92f0017133c2d31fbd527bab7b08d4d49a582143.tar.gz
Refs #34534 -- Reduced Add/RemoveConstraint and Add/RenameIndex operations when optimizing migrations.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/operations/models.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
index 9c5bd5fbcb..b18ef55369 100644
--- a/django/db/migrations/operations/models.py
+++ b/django/db/migrations/operations/models.py
@@ -929,6 +929,9 @@ class AddIndex(IndexOperation):
def reduce(self, operation, app_label):
if isinstance(operation, RemoveIndex) and self.index.name == operation.name:
return []
+ if isinstance(operation, RenameIndex) and self.index.name == operation.old_name:
+ self.index.name = operation.new_name
+ return [AddIndex(model_name=self.model_name, index=self.index)]
return super().reduce(operation, app_label)
@@ -1164,6 +1167,15 @@ class AddConstraint(IndexOperation):
def migration_name_fragment(self):
return "%s_%s" % (self.model_name_lower, self.constraint.name.lower())
+ def reduce(self, operation, app_label):
+ if (
+ isinstance(operation, RemoveConstraint)
+ and self.model_name_lower == operation.model_name_lower
+ and self.constraint.name == operation.name
+ ):
+ return []
+ return super().reduce(operation, app_label)
+
class RemoveConstraint(IndexOperation):
option_name = "constraints"