mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Add database upgrading mechanism for adding the audit table.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
92c3c86be4
commit
1dbe6c83c3
3 changed files with 40 additions and 1 deletions
21
advanced/Scripts/database_migration/gravity-db.sh
Normal file
21
advanced/Scripts/database_migration/gravity-db.sh
Normal 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
|
||||||
|
}
|
9
advanced/Scripts/database_migration/gravity/1_to_2.sql
Normal file
9
advanced/Scripts/database_migration/gravity/1_to_2.sql
Normal 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';
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue