Skip to content

Commit

Permalink
#290 Fix silk_clear_request_log errors on Postgres (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmonkey22 authored and albertyw committed Jun 13, 2018
1 parent 33f2d28 commit 639da91
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions silk/management/commands/silk_clear_request_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ def delete_model(model):
table = model._meta.db_table
if 'mysql' in engine or 'postgresql' in engine:
# Use "TRUNCATE" on the table
cursor = connection.cursor()
if 'mysql' in engine:
cursor.execute("SET FOREIGN_KEY_CHECKS=0;")
if 'postgres' in engine:
cursor.execute("ALTER TABLE %s DISABLE TRIGGER ALL;", [table])
cursor.execute("TRUNCATE TABLE %s", [table])
if 'mysql' in engine:
cursor.execute("SET FOREIGN_KEY_CHECKS=1;")
if 'postgres' in engine:
cursor.execute("ALTER TABLE %s ENABLE TRIGGER ALL;", [table])
with connection.cursor() as cursor:
if 'mysql' in engine:
cursor.execute("SET FOREIGN_KEY_CHECKS=0;")
cursor.execute("TRUNCATE TABLE {0}".format(table))
cursor.execute("SET FOREIGN_KEY_CHECKS=1;")
elif 'postgres' in engine:
cursor.execute("ALTER TABLE {0} DISABLE TRIGGER ALL;".format(table))
cursor.execute("TRUNCATE TABLE {0} CASCADE".format(table))
cursor.execute("ALTER TABLE {0} ENABLE TRIGGER ALL;".format(table))
return

# Manually delete rows because sqlite does not support TRUNCATE and
Expand Down

0 comments on commit 639da91

Please sign in to comment.