From 2180531a84516f6720985f034fc8d0cdb589e6a7 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 29 Apr 2019 19:43:35 +0200 Subject: [PATCH] Add trigger for automatic updates of the date_modified column and improve formating in the gravity.db template Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 37 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index c1066f33..dc0f23ed 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -8,21 +8,38 @@ CREATE TABLE info (property TEXT NOT NULL, value TEXT NOT NULL); INSERT INTO info VALUES("version","1"); CREATE VIEW vw_gravity AS SELECT DISTINCT a.domain -FROM gravity a -WHERE a.domain NOT IN (SELECT domain from whitelist WHERE enabled == 1); + FROM gravity a + WHERE a.domain NOT IN (SELECT domain from whitelist WHERE enabled == 1); CREATE VIEW vw_whitelist AS SELECT DISTINCT a.domain -FROM whitelist a -WHERE a.enabled == 1; + FROM whitelist a + WHERE a.enabled == 1; +CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist + BEGIN + UPDATE whitelist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; + END; CREATE VIEW vw_blacklist AS SELECT DISTINCT a.domain -FROM blacklist a -WHERE a.enabled == 1 AND a.domain NOT IN vw_whitelist; + FROM blacklist a + WHERE a.enabled == 1 AND a.domain NOT IN vw_whitelist; +CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist + BEGIN + UPDATE blacklist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; + END; CREATE VIEW vw_regex AS SELECT DISTINCT a.domain -FROM regex a -WHERE a.enabled == 1; + FROM regex a + WHERE a.enabled == 1; +CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex + BEGIN + UPDATE regex SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain; + END; CREATE VIEW vw_adlists AS SELECT DISTINCT a.address -FROM adlists a -WHERE a.enabled == 1; + FROM adlists a + WHERE a.enabled == 1; +CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists + BEGIN + UPDATE adlists SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE address = NEW.address; + END; +