Skip to content

Commit 78239f9

Browse files
committed
implement SchemaEditor.alter_index_together()
1 parent d1dfe11 commit 78239f9

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
@@ -110,8 +110,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
110110
# AlterField (unique)
111111
"schema.tests.SchemaTests.test_unique",
112112
"schema.tests.SchemaTests.test_unique_and_reverse_m2m",
113-
# alter_index_together
114-
"schema.tests.SchemaTests.test_index_together",
115113
# alter_unique_together
116114
"schema.tests.SchemaTests.test_unique_together",
117115
# 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)