Add database upgrading mechanism for adding the audit table.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2019-07-05 13:54:18 +02:00
parent 92c3c86be4
commit 1dbe6c83c3
No known key found for this signature in database
GPG key ID: 00135ACBD90B28DD
3 changed files with 40 additions and 1 deletions

View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090
# Pi-hole: A black hole for Internet advertisements
# (c) 2019 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
# Updates gravity.db database
#
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
upgrade_gravityDB(){
version=$(sqlite3 "$1" "SELECT "value" FROM "info" WHERE "property" = 'version';")
echo $version
case "$version" in
1)
sqlite3 "$1" < "/etc/.pihole/advanced/Scripts/database_migration/gravity/1_to_2.sql"
;;
esac
}

View file

@ -0,0 +1,9 @@
CREATE TABLE audit
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
domain TEXT UNIQUE NOT NULL,
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
comment TEXT
);
UPDATE info SET value = 2 WHERE property = 'version';

View file

@ -80,13 +80,22 @@ CREATE TABLE gravity
( (
domain TEXT PRIMARY KEY domain TEXT PRIMARY KEY
); );
CREATE TABLE audit
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
domain TEXT UNIQUE NOT NULL,
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
comment TEXT
);
CREATE TABLE info CREATE TABLE info
( (
property TEXT PRIMARY KEY, property TEXT PRIMARY KEY,
value TEXT NOT NULL value TEXT NOT NULL
); );
INSERT INTO info VALUES("version","1"); INSERT INTO info VALUES("version","2");
CREATE VIEW vw_gravity AS SELECT domain CREATE VIEW vw_gravity AS SELECT domain
FROM gravity FROM gravity