From 9135cffaa4b128cd3dd34fbc4edc275b9042cdd7 Mon Sep 17 00:00:00 2001 From: bjoern Date: Tue, 13 Feb 2024 23:00:47 +0100 Subject: [PATCH] do not change db schema in an incompatible way (#5254) PR #5099 removed some columns in the database that were actually in use. usually, to not worsen UX unnecessarily (releases take time - in between, "Add Second Device", "Backup" etc. would fail), we try to avoid such schema changes (checking for db-version would avoid import etc. but would still worse UX), see discussion at #2294. these are the errors, the user will be confronted with otherwise: it is not great to maintain the old columns, but well :) as no official releases with newer cores are rolled out yet, i think, it is fine to change the "107" migration and not copy things a second time in a newer migration. (this issue happens to me during testing, and is probably also the issue reported by @lk108 for ubuntu-touch) --- src/key.rs | 12 +++++++++--- src/sql/migrations.rs | 11 +++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/key.rs b/src/key.rs index 865f535234..eb1bfb49a3 100644 --- a/src/key.rs +++ b/src/key.rs @@ -294,11 +294,17 @@ pub async fn store_self_keypair( KeyPairUse::ReadOnly => false, }; + // `addr` and `is_default` written for compatibility with older versions, + // until new cores are rolled out everywhere. + // otherwise "add second device" or "backup" may break. + // moreover, this allows downgrades to the previous version. + // writing of `addr` and `is_default` can be removed ~ 2024-08 + let addr = keypair.addr.to_string(); transaction .execute( - "INSERT OR REPLACE INTO keypairs (public_key, private_key) - VALUES (?,?)", - (&public_key, &secret_key), + "INSERT OR REPLACE INTO keypairs (public_key, private_key, addr, is_default) + VALUES (?,?,?,?)", + (&public_key, &secret_key, addr, is_default), ) .context("Failed to insert keypair")?; diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index 090cedc2ff..8e96859572 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -900,6 +900,17 @@ CREATE INDEX msgs_status_updates_index2 ON msgs_status_updates (uid); .await?; } + if dbversion < 110 { + sql.execute_migration( + "ALTER TABLE keypairs ADD COLUMN addr TEXT DEFAULT '' COLLATE NOCASE; + ALTER TABLE keypairs ADD COLUMN is_default INTEGER DEFAULT 0; + ALTER TABLE keypairs ADD COLUMN created INTEGER DEFAULT 0; + UPDATE keypairs SET addr=(SELECT value FROM config WHERE keyname='configured_addr'), is_default=1;", + 110, + ) + .await?; + } + let new_version = sql .get_raw_config_int(VERSION_CFG) .await?