mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Add date_updated field in adlist table set when a list changes.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
17ed5398e6
commit
4fd412d7c3
4 changed files with 33 additions and 2 deletions
|
@ -110,4 +110,10 @@ upgrade_gravityDB(){
|
||||||
sqlite3 "${database}" < "${scriptPath}/11_to_12.sql"
|
sqlite3 "${database}" < "${scriptPath}/11_to_12.sql"
|
||||||
version=12
|
version=12
|
||||||
fi
|
fi
|
||||||
|
if [[ "$version" == "12" ]]; then
|
||||||
|
# Add column date_updated to alist table
|
||||||
|
echo -e " ${INFO} Upgrading gravity database from version 12 to 13"
|
||||||
|
sqlite3 "${database}" < "${scriptPath}/12_to_13.sql"
|
||||||
|
version=12
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
11
advanced/Scripts/database_migration/gravity/12_to_13.sql
Normal file
11
advanced/Scripts/database_migration/gravity/12_to_13.sql
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.timeout 30000
|
||||||
|
|
||||||
|
PRAGMA FOREIGN_KEYS=OFF;
|
||||||
|
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE adlist ADD COLUMN date_updated INTEGER;
|
||||||
|
|
||||||
|
UPDATE info SET value = 13 WHERE property = 'version';
|
||||||
|
|
||||||
|
COMMIT;
|
|
@ -31,7 +31,8 @@ CREATE TABLE adlist
|
||||||
enabled BOOLEAN NOT NULL DEFAULT 1,
|
enabled BOOLEAN NOT NULL DEFAULT 1,
|
||||||
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
||||||
date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
||||||
comment TEXT
|
comment TEXT,
|
||||||
|
date_updated INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int))
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE adlist_by_group
|
CREATE TABLE adlist_by_group
|
||||||
|
@ -53,7 +54,7 @@ CREATE TABLE info
|
||||||
value TEXT NOT NULL
|
value TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO "info" VALUES('version','12');
|
INSERT INTO "info" VALUES('version','13');
|
||||||
|
|
||||||
CREATE TABLE domain_audit
|
CREATE TABLE domain_audit
|
||||||
(
|
(
|
||||||
|
|
13
gravity.sh
13
gravity.sh
|
@ -207,6 +207,17 @@ database_table_from_file() {
|
||||||
echo -e " ${CROSS} Unable to remove ${tmpFile}"
|
echo -e " ${CROSS} Unable to remove ${tmpFile}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Update timestamp of last update of this list. We store this in the "old" database as all values in the new database will later be overwritten
|
||||||
|
database_adlist_updated() {
|
||||||
|
output=$( { printf ".timeout 30000\\nUPDATE adlist SET date_updated = (cast(strftime('%%s', 'now') as int)) WHERE id = %i;\\n" "${1}" | sqlite3 "${gravityDBfile}"; } 2>&1 )
|
||||||
|
status="$?"
|
||||||
|
|
||||||
|
if [[ "${status}" -ne 0 ]]; then
|
||||||
|
echo -e "\\n ${CROSS} Unable to update timestamp of adlist with ID ${1} in database ${gravityDBfile}\\n ${output}"
|
||||||
|
gravity_Cleanup "error"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Migrate pre-v5.0 list files to database-based Pi-hole versions
|
# Migrate pre-v5.0 list files to database-based Pi-hole versions
|
||||||
migrate_to_database() {
|
migrate_to_database() {
|
||||||
# Create database file only if not present
|
# Create database file only if not present
|
||||||
|
@ -555,6 +566,8 @@ gravity_DownloadBlocklistFromUrl() {
|
||||||
gravity_ParseFileIntoDomains "${patternBuffer}" "${saveLocation}"
|
gravity_ParseFileIntoDomains "${patternBuffer}" "${saveLocation}"
|
||||||
# Add domains to database table file
|
# Add domains to database table file
|
||||||
parseList "${adlistID}" "${saveLocation}" "${target}"
|
parseList "${adlistID}" "${saveLocation}" "${target}"
|
||||||
|
# Update date_updated field in gravity database table
|
||||||
|
database_adlist_updated "${adlistID}"
|
||||||
else
|
else
|
||||||
# Fall back to previously cached list if $patternBuffer is empty
|
# Fall back to previously cached list if $patternBuffer is empty
|
||||||
echo -e " ${INFO} Received empty file: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
|
echo -e " ${INFO} Received empty file: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
|
||||||
|
|
Loading…
Reference in a new issue