Compare commits
No commits in common. "302af9cda4d4840040938a0d4a0012d6682e06b0" and "46fb46bf26b8ff964e231340c2ad11b4ad1970df" have entirely different histories.
302af9cda4
...
46fb46bf26
2 changed files with 8 additions and 18 deletions
|
|
@ -45,16 +45,12 @@ 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:
|
||||||
for sql in (
|
sql = "SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \
|
||||||
"SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \
|
"WHERE indexdef LIKE '%ON {table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column)
|
||||||
"WHERE indexdef LIKE '%ON {table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column),
|
cursor.execute(sql)
|
||||||
"SELECT indexname, indexdef FROM pg_catalog.pg_indexes " + \
|
for r in cursor:
|
||||||
"WHERE indexdef LIKE '%ON public.{table}%' AND indexdef LIKE '%{column}%'".format(table=table, column=column),
|
if 'USING gin' not in r[1]:
|
||||||
):
|
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
|
||||||
|
|
|
||||||
|
|
@ -25,20 +25,14 @@ def _to_json(python_object):
|
||||||
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
|
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||||
raise TypeError(u'%s %s is not JSON serializable' % (repr(python_object), type(python_object)))
|
raise TypeError(u'%s %s is not JSON serializable' % (repr(python_object), type(python_object)))
|
||||||
|
|
||||||
def json_dump(data, fp, indent=4):
|
|
||||||
return json.dump(data, fp, indent=indent, default=_to_json, ensure_ascii=False)
|
|
||||||
|
|
||||||
def json_dumps(data, indent=4):
|
|
||||||
return json.dumps(data, indent=indent, default=_to_json, ensure_ascii=False)
|
|
||||||
|
|
||||||
def render_to_json_response(dictionary, content_type="application/json", status=200):
|
def render_to_json_response(dictionary, content_type="application/json", status=200):
|
||||||
indent = None
|
indent = None
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
content_type = "text/javascript"
|
content_type = "text/javascript"
|
||||||
indent = 2
|
indent = 2
|
||||||
if getattr(settings, 'JSON_DEBUG', False):
|
if getattr(settings, 'JSON_DEBUG', False):
|
||||||
print(json_dumps(dictionary, indent=2).encode('utf-8'))
|
print(json.dumps(dictionary, indent=2, default=_to_json, ensure_ascii=False).encode('utf-8'))
|
||||||
response = json_dumps(dictionary, indent=indent)
|
response = json.dumps(dictionary, indent=indent, default=_to_json, ensure_ascii=False)
|
||||||
if not isinstance(response, bytes):
|
if not isinstance(response, bytes):
|
||||||
response = response.encode('utf-8')
|
response = response.encode('utf-8')
|
||||||
return HttpResponse(response, content_type=content_type, status=status)
|
return HttpResponse(response, content_type=content_type, status=status)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue