1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 14:58:08 +00:00

Add id (primary key, autoincrement) field to lists tables

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2019-05-01 17:31:34 +02:00
parent b372f808dd
commit 983117d788
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
2 changed files with 29 additions and 5 deletions

View File

@ -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 whitelist (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
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); domain TEXT UNIQUE NOT NULL,
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); enabled BOOLEAN NOT NULL DEFAULT 1,
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); 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 gravity (domain TEXT UNIQUE NOT NULL);
CREATE TABLE info (property TEXT NOT NULL, value TEXT NOT NULL); CREATE TABLE info (property TEXT NOT NULL, value TEXT NOT NULL);

View File

@ -118,12 +118,16 @@ database_table_from_file() {
inputfile="${source}" inputfile="${source}"
else else
# Apply format for white-, blacklist, regex, and adlists tables # Apply format for white-, blacklist, regex, and adlists tables
local rowid
declare -i rowid
rowid=1
# Read file line by line # Read file line by line
grep -v '^ *#' < "${source}" | while IFS= read -r domain grep -v '^ *#' < "${source}" | while IFS= read -r domain
do do
# Only add non-empty lines # Only add non-empty lines
if [[ ! -z "${domain}" ]]; then if [[ ! -z "${domain}" ]]; then
echo "\"${domain}\",1,${timestamp},${timestamp}" >> "${tmpFile}" echo "${rowid},\"${domain}\",1,${timestamp},${timestamp}" >> "${tmpFile}"
rowid+=1
fi fi
done done
inputfile="${tmpFile}" inputfile="${tmpFile}"