Skip to content

Commit

Permalink
implement SchemaEditor.alter_index_together()
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Sep 13, 2024
1 parent 71a723b commit fa74fae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 0 additions & 2 deletions django_mongodb/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
# AlterField (unique)
"schema.tests.SchemaTests.test_unique",
"schema.tests.SchemaTests.test_unique_and_reverse_m2m",
# alter_index_together
"schema.tests.SchemaTests.test_index_together",
# alter_unique_together
"schema.tests.SchemaTests.test_unique_together",
# ManyToManyField
Expand Down
13 changes: 12 additions & 1 deletion django_mongodb/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ def remove_field(self, model, field):
self.connection.database[model._meta.db_table].update_many({}, {"$unset": {column: ""}})

def alter_index_together(self, model, old_index_together, new_index_together):
pass
olds = {tuple(fields) for fields in old_index_together}
news = {tuple(fields) for fields in new_index_together}
# Deleted indexes
for field_names in olds.difference(news):
idx = Index(fields=field_names)
idx.set_name_with_model(model)
self.remove_index(model, idx)
# Created indexes
for field_names in news.difference(olds):
idx = Index(fields=field_names)
idx.set_name_with_model(model)
self.add_index(model, idx)

def alter_unique_together(self, model, old_unique_together, new_unique_together):
pass
Expand Down

0 comments on commit fa74fae

Please sign in to comment.