Use views for all tables and set disabled column to false for those tables that support it

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2019-02-03 14:14:14 +01:00
parent 710036adae
commit dcf0a605cf
No known key found for this signature in database
GPG key ID: FB60471F0575164A
2 changed files with 20 additions and 7 deletions

View file

@ -1,7 +1,5 @@
CREATE TABLE whitelist (domain TEXT UNIQUE NOT NULL, comment TEXT, disabled BOOLEAN DEFAULT 0, DateAdded DATETIME);
CREATE TABLE blacklist (domain TEXT UNIQUE NOT NULL, comment TEXT, disabled BOOLEAN DEFAULT 0, DateAdded DATETIME);
CREATE TABLE whitelist (domain TEXT UNIQUE NOT NULL, disabled BOOLEAN DEFAULT 0, comment TEXT, DateAdded DATETIME);
CREATE TABLE blacklist (domain TEXT UNIQUE NOT NULL, disabled BOOLEAN DEFAULT 0, comment TEXT, DateAdded DATETIME);
CREATE TABLE gravity (domain TEXT UNIQUE NOT NULL);
CREATE VIEW vw_gravity AS SELECT DISTINCT a.domain
@ -12,3 +10,7 @@ CREATE VIEW vw_blacklist AS SELECT DISTINCT a.domain
FROM blacklist a
WHERE a.disabled != 1 AND
a.domain NOT IN (SELECT domain from whitelist WHERE disabled != 1);
CREATE VIEW vw_whitelist AS SELECT DISTINCT a.domain
FROM whitelist a
WHERE a.disabled != 1;

View file

@ -115,16 +115,27 @@ gravity_store_in_database() {
gravity_Cleanup "error"
fi
# Store domains in gravity database
# Store domains in gravity database table ${table}
output=$( { sqlite3 "${gravityDBfile}" <<< ".import \"${source}\" ${table}"; } 2>&1 )
status="$?"
if [[ "${status}" -ne 0 ]]; then
echo -e "\\n ${CROSS} Unable to create ${table} database ${gravityDBfile}\\n ${output}"
echo -e "\\n ${CROSS} Unable to create ${table} in database ${gravityDBfile}\\n ${output}"
gravity_Cleanup "error"
fi
# Empty $adList if it already exists, otherwise, create it
if [ "$table" == "whitelist" ] || [ "$table" == "blacklist" ]; then
# Set disabled to false
output=$( { sqlite3 "${gravityDBfile}" <<< "UPDATE ${table} SET disabled = 0 WHERE disabled IS NULL;"; } 2>&1 )
status="$?"
if [[ "${status}" -ne 0 ]]; then
echo -e "\\n ${CROSS} Unable to set disabled states (${table}) in database ${gravityDBfile}\\n ${output}"
gravity_Cleanup "error"
fi
fi
# Empty $template if it already exists, otherwise, create it
output=$( { : > "${template}"; } 2>&1 )
status="$?"