From 86b3964bb9a3c895d1d52ac61f1a63bfe1e086ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 13 Aug 2015 21:49:54 +0300 Subject: [PATCH] SQLite version of trigger. --- hc/api/management/commands/ensuretriggers.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hc/api/management/commands/ensuretriggers.py b/hc/api/management/commands/ensuretriggers.py index 87321dd3..e5e5a50b 100644 --- a/hc/api/management/commands/ensuretriggers.py +++ b/hc/api/management/commands/ensuretriggers.py @@ -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")