Skip to content

Commit 9d9339d

Browse files
committed
implement SchemaEditor.alter_index_together()
1 parent 1c0706b commit 9d9339d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

django_mongodb/schema.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,30 @@ def _remove_field_index(self, model, field):
202202
)
203203
collection.drop_index(index_names[0])
204204

205+
def _remove_composed_index(self, model, field_names, constraint_kwargs):
206+
"""
207+
Remove the index on the given list of field_names created by
208+
index/unique_together, depending on constraint_kwargs.
209+
"""
210+
meta_constraint_names = {constraint.name for constraint in model._meta.constraints}
211+
meta_index_names = {constraint.name for constraint in model._meta.indexes}
212+
columns = [model._meta.get_field(field).column for field in field_names]
213+
constraint_names = self._constraint_names(
214+
model,
215+
columns,
216+
exclude=meta_constraint_names | meta_index_names,
217+
**constraint_kwargs,
218+
)
219+
if len(constraint_names) != 1:
220+
num_found = len(constraint_names)
221+
columns_str = ", ".join(columns)
222+
raise ValueError(
223+
f"Found wrong number ({num_found}) of constraints for "
224+
f"{model._meta.db_table}({columns_str})."
225+
)
226+
collection = self.connection.database[model._meta.db_table]
227+
collection.drop_index(constraint_names[0])
228+
205229
def add_constraint(self, model, constraint):
206230
pass
207231

0 commit comments

Comments
 (0)