Skip to content

Commit fa74fae

Browse files
committed
implement SchemaEditor.alter_index_together()
1 parent 71a723b commit fa74fae

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

django_mongodb/features.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
107107
# AlterField (unique)
108108
"schema.tests.SchemaTests.test_unique",
109109
"schema.tests.SchemaTests.test_unique_and_reverse_m2m",
110-
# alter_index_together
111-
"schema.tests.SchemaTests.test_index_together",
112110
# alter_unique_together
113111
"schema.tests.SchemaTests.test_unique_together",
114112
# ManyToManyField

django_mongodb/schema.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ def remove_field(self, model, field):
6565
self.connection.database[model._meta.db_table].update_many({}, {"$unset": {column: ""}})
6666

6767
def alter_index_together(self, model, old_index_together, new_index_together):
68-
pass
68+
olds = {tuple(fields) for fields in old_index_together}
69+
news = {tuple(fields) for fields in new_index_together}
70+
# Deleted indexes
71+
for field_names in olds.difference(news):
72+
idx = Index(fields=field_names)
73+
idx.set_name_with_model(model)
74+
self.remove_index(model, idx)
75+
# Created indexes
76+
for field_names in news.difference(olds):
77+
idx = Index(fields=field_names)
78+
idx.set_name_with_model(model)
79+
self.add_index(model, idx)
6980

7081
def alter_unique_together(self, model, old_unique_together, new_unique_together):
7182
pass

0 commit comments

Comments
 (0)