From 9cdd2a9f8b3c458d82ae033080571862b712ac3e Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sun, 3 Jan 2021 22:27:02 +0100 Subject: [PATCH] [db] Upgrade schema to 21.05 (change auth_keys in speaker table) --- src/db_init.h | 2 +- src/db_upgrade.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/db_init.h b/src/db_init.h index a72dbda6..a28463d2 100644 --- a/src/db_init.h +++ b/src/db_init.h @@ -26,7 +26,7 @@ * is a major upgrade. In other words minor version upgrades permit downgrading * forked-daapd after the database was upgraded. */ #define SCHEMA_VERSION_MAJOR 21 -#define SCHEMA_VERSION_MINOR 04 +#define SCHEMA_VERSION_MINOR 05 int db_init_indices(sqlite3 *hdl); diff --git a/src/db_upgrade.c b/src/db_upgrade.c index a1f477ad..d4df1127 100644 --- a/src/db_upgrade.c +++ b/src/db_upgrade.c @@ -1060,6 +1060,19 @@ static const struct db_upgrade_query db_upgrade_v2104_queries[] = { U_v2104_SCVER_MINOR, "set schema_version_minor to 04" }, }; +// Previously, the auth_key contained the public key twice +#define U_v2105_UPDATE_SPEAKERS_AUTH_KEY \ + "UPDATE speakers SET auth_key = SUBSTR(auth_key, LENGTH(auth_key) - 128 + 1, LENGTH(auth_key) + 1) WHERE LENGTH(auth_key) = 128 + 64;" +#define U_v2105_SCVER_MINOR \ + "UPDATE admin SET value = '05' WHERE key = 'schema_version_minor';" + +static const struct db_upgrade_query db_upgrade_v2105_queries[] = + { + { U_v2105_UPDATE_SPEAKERS_AUTH_KEY, "update table speakers auth_key length" }, + + { U_v2105_SCVER_MINOR, "set schema_version_minor to 05" }, + }; + int db_upgrade(sqlite3 *hdl, int db_ver) @@ -1237,6 +1250,14 @@ db_upgrade(sqlite3 *hdl, int db_ver) return -1; break; + /* FALLTHROUGH */ + + case 2104: + ret = db_generic_upgrade(hdl, db_upgrade_v2105_queries, ARRAY_SIZE(db_upgrade_v2105_queries)); + if (ret < 0) + return -1; + break; + default: DPRINTF(E_FATAL, L_DB, "No upgrade path from the current DB schema\n"); return -1;