diff --git a/src/key.rs b/src/key.rs index 865f53523..eb1bfb49a 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 090cedc2f..8e9685957 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?