fix findindex in postgresql 10

This commit is contained in:
j 2019-03-12 17:48:03 +00:00
parent 894a609f3f
commit 302af9cda4

View file

@ -45,12 +45,16 @@ class Command(BaseCommand):
indexes = connection.introspection.get_indexes(cursor, table) indexes = connection.introspection.get_indexes(cursor, table)
drop = [] drop = []
if column in indexes: if column in indexes:
sql = "SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \ for sql in (
"WHERE indexdef LIKE '%ON {table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column) "SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \
cursor.execute(sql) "WHERE indexdef LIKE '%ON {table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column),
for r in cursor: "SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \
if 'USING gin' not in r[1]: "WHERE indexdef LIKE '%ON public.{table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column),
drop.append(r[0]) ):
cursor.execute(sql)
for r in cursor:
if 'USING gin' not in r[1]:
drop.append(r[0])
if drop: if drop:
for idx in drop: for idx in drop:
sql = 'DROP INDEX ' + idx sql = 'DROP INDEX ' + idx