From cbc210b0145415a6aedfc28c6ae266fd0a85c3ec Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Jun 2019 17:05:33 +0200 Subject: [PATCH] Add adlist_groups and mark group_id columns as NOT NULL. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 22 +++++++++++++++++----- gravity.sh | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index ee0caa8e..e22cc44b 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -15,7 +15,7 @@ CREATE TABLE whitelist enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER DEFAULT 0, + group_id INTEGER NOT NULL DEFAULT 0, comment TEXT, FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); @@ -26,7 +26,7 @@ CREATE TABLE blacklist enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER DEFAULT 0, + group_id INTEGER NOT NULL DEFAULT 0, comment TEXT, FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); @@ -37,10 +37,19 @@ CREATE TABLE regex enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - group_id INTEGER DEFAULT 0, + group_id INTEGER NOT NULL DEFAULT 0, comment TEXT, FOREIGN KEY (group_id) REFERENCES domain_groups(id) ); + +CREATE TABLE adlist_groups +( + "id" INTEGER PRIMARY KEY AUTOINCREMENT, + "enabled" BOOLEAN NOT NULL DEFAULT 1, + "description" TEXT +); +INSERT INTO adlist_groups ("id","description") VALUES (0,'Standard group'); + CREATE TABLE adlists ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -48,7 +57,9 @@ CREATE TABLE adlists enabled BOOLEAN NOT NULL DEFAULT 1, date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), - comment TEXT + group_id INTEGER NOT NULL DEFAULT 0, + comment TEXT, + FOREIGN KEY (group_id) REFERENCES adlist_groups(id) ); CREATE TABLE gravity ( @@ -101,7 +112,8 @@ CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex CREATE VIEW vw_adlists AS SELECT a.address FROM adlists a - WHERE a.enabled == 1 + INNER JOIN adlist_groups b ON b.id = a.group_id + WHERE a.enabled = 1 AND b.enabled = 1 ORDER BY a.id; CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists diff --git a/gravity.sh b/gravity.sh index 1fe2b4e3..ce7aa6ba 100755 --- a/gravity.sh +++ b/gravity.sh @@ -120,7 +120,7 @@ database_table_from_file() { do # Only add non-empty lines if [[ ! -z "${domain}" ]]; then - echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}" + echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},0,\"Migrated from ${source}\"" >> "${tmpFile}" rowid+=1 fi done