From 7cc35d3b048657e236911805ea1d26dc5949bd87 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 7 May 2020 17:55:35 +0200 Subject: [PATCH] Add update to gravity database version 12, renaming the Unassociated group to Default group. Signed-off-by: DL6ER --- .../Scripts/database_migration/gravity-db.sh | 6 ++++++ .../database_migration/gravity/11_to_12.sql | 19 +++++++++++++++++++ advanced/Templates/gravity.db.sql | 6 +++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 advanced/Scripts/database_migration/gravity/11_to_12.sql diff --git a/advanced/Scripts/database_migration/gravity-db.sh b/advanced/Scripts/database_migration/gravity-db.sh index 8a669429..70090a3b 100644 --- a/advanced/Scripts/database_migration/gravity-db.sh +++ b/advanced/Scripts/database_migration/gravity-db.sh @@ -104,4 +104,10 @@ upgrade_gravityDB(){ sqlite3 "${database}" < "${scriptPath}/10_to_11.sql" version=11 fi + if [[ "$version" == "11" ]]; then + # Rename group 0 from "Unassociated" to "Default" + echo -e " ${INFO} Upgrading gravity database from version 11 to 12" + sqlite3 "${database}" < "${scriptPath}/11_to_12.sql" + version=12 + fi } diff --git a/advanced/Scripts/database_migration/gravity/11_to_12.sql b/advanced/Scripts/database_migration/gravity/11_to_12.sql new file mode 100644 index 00000000..45fbc845 --- /dev/null +++ b/advanced/Scripts/database_migration/gravity/11_to_12.sql @@ -0,0 +1,19 @@ +.timeout 30000 + +PRAGMA FOREIGN_KEYS=OFF; + +BEGIN TRANSACTION; + +UPDATE "group" SET name = 'Default' WHERE id = 0; +UPDATE "group" SET description = 'The default group' WHERE id = 0; + +DROP TRIGGER IF EXISTS tr_group_zero; + +CREATE TRIGGER tr_group_zero AFTER DELETE ON "group" + BEGIN + INSERT OR IGNORE INTO "group" (id,enabled,name,description) VALUES (0,1,'Default','The default group'); + END; + +UPDATE info SET value = 12 WHERE property = 'version'; + +COMMIT; \ No newline at end of file diff --git a/advanced/Templates/gravity.db.sql b/advanced/Templates/gravity.db.sql index e543bd19..27b8797f 100644 --- a/advanced/Templates/gravity.db.sql +++ b/advanced/Templates/gravity.db.sql @@ -10,7 +10,7 @@ CREATE TABLE "group" date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)), description TEXT ); -INSERT INTO "group" (id,enabled,name) VALUES (0,1,'Unassociated'); +INSERT INTO "group" (id,enabled,name,description) VALUES (0,1,'Default','The default group'); CREATE TABLE domainlist ( @@ -52,7 +52,7 @@ CREATE TABLE info value TEXT NOT NULL ); -INSERT INTO "info" VALUES('version','11'); +INSERT INTO "info" VALUES('version','12'); CREATE TABLE domain_audit ( @@ -167,7 +167,7 @@ CREATE TRIGGER tr_group_update AFTER UPDATE ON "group" CREATE TRIGGER tr_group_zero AFTER DELETE ON "group" BEGIN - INSERT OR IGNORE INTO "group" (id,enabled,name) VALUES (0,1,'Unassociated'); + INSERT OR IGNORE INTO "group" (id,enabled,name) VALUES (0,1,'Default'); END; CREATE TRIGGER tr_domainlist_delete AFTER DELETE ON domainlist