Browse Source

SQLite version of trigger.

pull/7/head
Pēteris Caune 9 years ago
parent
commit
86b3964bb9
1 changed files with 19 additions and 0 deletions
  1. +19
    -0
      hc/api/management/commands/ensuretriggers.py

+ 19
- 0
hc/api/management/commands/ensuretriggers.py View File

@ -32,6 +32,22 @@ def _mysql(cursor):
""")
def _sqlite(cursor):
cursor.execute("""
DROP TRIGGER IF EXISTS update_alert_after;
""")
cursor.execute("""
CREATE TRIGGER update_alert_after
AFTER UPDATE OF last_ping, timeout, grace ON api_check
FOR EACH ROW BEGIN
UPDATE api_check
SET alert_after = datetime(strftime('%s', last_ping) + timeout/1000000 + grace/1000000, 'unixepoch')
WHERE id = OLD.id;
END;
""")
class Command(BaseCommand):
help = 'Ensures triggers exist in database'
@ -44,3 +60,6 @@ class Command(BaseCommand):
if connection.vendor == "mysql":
_mysql(cursor)
print("Created MySQL trigger")
if connection.vendor == "sqlite":
_sqlite(cursor)
print("Created SQLite trigger")

Loading…
Cancel
Save