1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Refs #20888 -- Added index order introspection.

This commit is contained in:
Akshesh
2016-07-26 06:34:28 +05:30
committed by Tim Graham
parent 5eab1f6f83
commit f842d1011c
8 changed files with 78 additions and 16 deletions

View File

@@ -255,6 +255,18 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
"index": True,
}
constraints[index]['columns'].append(column)
# Add column orders for indexes
if constraints[index]['index'] and not constraints[index]['unique']:
cursor.execute(
"SELECT sql FROM sqlite_master "
"WHERE type='index' AND name=%s" % self.connection.ops.quote_name(index)
)
orders = []
# There would be only 1 row to loop over
for sql, in cursor.fetchall():
order_info = sql.split('(')[-1].split(')')[0].split(',')
orders = ['DESC' if info.endswith('DESC') else 'ASC' for info in order_info]
constraints[index]['orders'] = orders
# Get the PK
pk_column = self.get_primary_key_column(cursor, table_name)
if pk_column: