Ticket #36632: show_indexes.py

File show_indexes.py, 663 bytes (added by Michael Herrmann, 4 hours ago)
Line 
1#!venv/bin/python
2
3from os.path import dirname, join
4
5import os
6import sys
7
8sys.path.append(join(dirname(__file__), 'mysite'))
9
10os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
11
12import django
13django.setup()
14
15from django.db import connection
16
17cursor = connection.cursor()
18cursor.execute("SELECT name FROM sqlite_master WHERE type='index' and name LIKE 'polls_%';")
19indexes = cursor.fetchall()
20
21for index in indexes:
22 index_name = index[0]
23 cursor.execute(f"PRAGMA index_info({index_name});")
24 info = cursor.fetchall()
25 print(f"\nIndex: {index_name}")
26 for col in info:
27 print(f" Column {col[0]}: {col[2]} (cid: {col[1]})")
Back to Top