Skip to content

Commit

Permalink
Revert "Remove deprecated meta.index_together field"
Browse files Browse the repository at this point in the history
This reverts commit b1e2a16.
  • Loading branch information
mShan0 committed May 24, 2024
1 parent b1e2a16 commit b35ccc6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions mssql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ def alter_unique_together(self, model, old_unique_together, new_unique_together)
def _model_indexes_sql(self, model):
"""
Return a list of all index SQL statements (field indexes,
Meta.indexes) for the specified model.
index_together, Meta.indexes) for the specified model.
"""
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
return []
output = []
for field in model._meta.local_fields:
output.extend(self._field_indexes_sql(model, field))

for field_names in model._meta.indexes:
for field_names in model._meta.index_together:
fields = [model._meta.get_field(field) for field in field_names]
output.append(self._create_index_sql(model, fields, suffix="_idx"))

Expand Down Expand Up @@ -792,7 +792,7 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
if old_field.db_index and new_field.db_index:
index_columns.append([old_field])
else:
for fields in model._meta.indexes:
for fields in model._meta.index_together:
columns = [model._meta.get_field(field) for field in fields]
if old_field.column in [c.column for c in columns]:
index_columns.append(columns)
Expand Down Expand Up @@ -917,7 +917,7 @@ def _delete_indexes(self, model, old_field, new_field):
index_columns.append([old_field.column])
elif old_field.null != new_field.null:
index_columns.append([old_field.column])
for fields in model._meta.indexes:
for fields in model._meta.index_together:
columns = [model._meta.get_field(field).column for field in fields]
if old_field.column in columns:
index_columns.append(columns)
Expand Down Expand Up @@ -1322,7 +1322,7 @@ def create_model(self, model):
model, field, field_type, field.db_comment
)
)
# Add any field index and indexes's (deferred as SQLite3 _remake_table needs it)
# Add any field index and index_together's (deferred as SQLite3 _remake_table needs it)
self.deferred_sql.extend(self._model_indexes_sql(model))
self.deferred_sql = list(set(self.deferred_sql))

Expand Down
6 changes: 3 additions & 3 deletions testapp/tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TestCorrectIndexes(TestCase):
def test_correct_indexes_exist(self):
"""
Check there are the correct number of indexes for each field after all migrations
by comparing what the model says (e.g. `db_index=True` / `indexes` etc.)
by comparing what the model says (e.g. `db_index=True` / `index_together` etc.)
with the actual constraints found in the database.
This acts as a general regression test for issues such as:
- duplicate index created (e.g. https://github.com/microsoft/mssql-django/issues/77)
Expand Down Expand Up @@ -115,9 +115,9 @@ def test_correct_indexes_exist(self):
expected_index_causes = []
if field.db_index:
expected_index_causes.append('db_index=True')
for field_names in model_cls._meta.indexes:
for field_names in model_cls._meta.index_together:
if field.name in field_names:
expected_index_causes.append(f'indexes[{field_names}]')
expected_index_causes.append(f'index_together[{field_names}]')
if field._unique and field.null:
# This is implemented using a (filtered) unique index (not a constraint) to get ANSI NULL behaviour
expected_index_causes.append('unique=True & null=True')
Expand Down

0 comments on commit b35ccc6

Please sign in to comment.