From 983117d788bd32ef1521a5c2da3088a2039e23bf Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 1 May 2019 17:31:34 +0200 Subject: [PATCH] Add id (primary key, autoincrement) field to lists tables Signed-off-by: DL6ER --- advanced/Templates/gravity.db.sql | 28 ++++++++++++++++++++++++---- gravity.sh | 6 +++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index 0960018b..65bd7448 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -1,7 +1,27 @@ -CREATE TABLE whitelist (domain TEXT UNIQUE NOT NULL, 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); -CREATE TABLE blacklist (domain TEXT UNIQUE NOT NULL, 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); -CREATE TABLE regex (domain TEXT UNIQUE NOT NULL, 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); -CREATE TABLE adlists (address TEXT UNIQUE NOT NULL, 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); +CREATE TABLE whitelist (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + domain TEXT UNIQUE NOT NULL, + 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); +CREATE TABLE blacklist (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + domain TEXT UNIQUE NOT NULL, + 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); +CREATE TABLE regex (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + domain TEXT UNIQUE NOT NULL, + 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); +CREATE TABLE adlists (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + address TEXT UNIQUE NOT NULL, + 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); CREATE TABLE gravity (domain TEXT UNIQUE NOT NULL); CREATE TABLE info (property TEXT NOT NULL, value TEXT NOT NULL); diff --git a/gravity.sh b/gravity.sh index 9f4065e7..c1eb0720 100755 --- a/gravity.sh +++ b/gravity.sh @@ -118,12 +118,16 @@ database_table_from_file() { inputfile="${source}" else # Apply format for white-, blacklist, regex, and adlists tables + local rowid + declare -i rowid + rowid=1 # Read file line by line grep -v '^ *#' < "${source}" | while IFS= read -r domain do # Only add non-empty lines if [[ ! -z "${domain}" ]]; then - echo "\"${domain}\",1,${timestamp},${timestamp}" >> "${tmpFile}" + echo "${rowid},\"${domain}\",1,${timestamp},${timestamp}" >> "${tmpFile}" + rowid+=1 fi done inputfile="${tmpFile}"