From 3cb4f6d9d4980c66a025f0e038acee9c3f3a20c4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 26 Sep 2019 13:50:54 +0200 Subject: [PATCH 1/2] We cannot create vw_gravity before having created vw_whitelist as the former depends onthe later. This commit changes the order in which the tables are created. Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 09d581f0..d0c744f4 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -89,10 +89,6 @@ CREATE TABLE info INSERT INTO info VALUES("version","1"); -CREATE VIEW vw_gravity AS SELECT domain - FROM gravity - WHERE domain NOT IN (SELECT domain from vw_whitelist); - CREATE VIEW vw_whitelist AS SELECT DISTINCT domain FROM whitelist LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id @@ -141,3 +137,6 @@ CREATE TRIGGER tr_adlist_update AFTER UPDATE ON adlist UPDATE adlist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE address = NEW.address; END; +CREATE VIEW vw_gravity AS SELECT domain + FROM gravity + WHERE domain NOT IN (SELECT domain from vw_whitelist); From 2e0370367cacd89a76f4a75954f70dc1f070ff07 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 26 Sep 2019 14:02:20 +0200 Subject: [PATCH 2/2] Print when we upgrade gravity database version. This will make possibly failed upgrades easier to debug. Signed-off-by: DL6ER --- advanced/Scripts/database_migration/gravity-db.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/database_migration/gravity-db.sh b/advanced/Scripts/database_migration/gravity-db.sh index a82d0d51..0fe90d8a 100644 --- a/advanced/Scripts/database_migration/gravity-db.sh +++ b/advanced/Scripts/database_migration/gravity-db.sh @@ -22,6 +22,7 @@ upgrade_gravityDB(){ if [[ "$version" == "1" ]]; then # This migration script upgrades the gravity.db file by # adding the domain_audit table + echo -e " ${INFO} Upgrading gravity database from version 1 to 2" sqlite3 "${database}" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/1_to_2.sql" version=2 @@ -36,6 +37,7 @@ upgrade_gravityDB(){ # This migration script upgrades the gravity.db file by # renaming the regex table to regex_blacklist, and # creating a new regex_whitelist table + corresponding linking table and views + echo -e " ${INFO} Upgrading gravity database from version 2 to 3" sqlite3 "${database}" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/2_to_3.sql" version=3 fi