Monkey patch accounts table aindex is missing
This commit is contained in:
parent
4838a6925d
commit
259efc0526
23
src/db.rs
23
src/db.rs
|
@ -851,11 +851,6 @@ impl DbAdapter {
|
|||
}
|
||||
|
||||
pub fn get_full_backup(&self, coin: u8) -> anyhow::Result<Vec<AccountBackup>> {
|
||||
let _ = self.connection.execute(
|
||||
"ALTER TABLE accounts ADD COLUMN aindex INT NOT NULL DEFAULT 0",
|
||||
[],
|
||||
); // ignore error
|
||||
|
||||
let mut statement = self.connection.prepare(
|
||||
"SELECT name, seed, aindex, a.sk AS z_sk, ivk, a.address AS z_addr, t.sk as t_sk, t.address AS t_addr FROM accounts a LEFT JOIN taddrs t ON a.id_account = t.account")?;
|
||||
let rows = statement.query_map([], |r| {
|
||||
|
@ -1141,6 +1136,15 @@ pub struct AccountInfo {
|
|||
pub sapling_tree: String,
|
||||
}
|
||||
|
||||
pub struct AccountData {
|
||||
pub name: String,
|
||||
pub seed: Option<String>,
|
||||
pub sk: Option<String>,
|
||||
pub fvk: String,
|
||||
pub address: String,
|
||||
pub aindex: u32,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::db::{DbAdapter, ReceivedNote, DEFAULT_DB_PATH};
|
||||
|
@ -1191,12 +1195,3 @@ mod tests {
|
|||
println!("{}", balance);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AccountData {
|
||||
pub name: String,
|
||||
pub seed: Option<String>,
|
||||
pub sk: Option<String>,
|
||||
pub fvk: String,
|
||||
pub address: String,
|
||||
pub aindex: u32,
|
||||
}
|
||||
|
|
|
@ -182,5 +182,23 @@ pub fn init_db(connection: &Connection) -> anyhow::Result<()> {
|
|||
log::info!("Database migrated");
|
||||
}
|
||||
|
||||
// We may get a database that has no valid schema version from a version of single currency Z/YWallet
|
||||
// because we kept the same app name in Google/Apple Stores. The upgraded app fails to recognize the db tables
|
||||
// At least we monkey patch the accounts table to let the user access the backup page and recover his seed phrase
|
||||
let c = connection.query_row(
|
||||
"SELECT COUNT(*) FROM pragma_table_info('accounts') WHERE name = 'aindex'",
|
||||
params![],
|
||||
|row| {
|
||||
let c: u32 = row.get(0)?;
|
||||
Ok(c)
|
||||
},
|
||||
)?;
|
||||
if c == 0 {
|
||||
connection.execute(
|
||||
"ALTER TABLE accounts ADD aindex INTEGER NOT NULL DEFAULT (0)",
|
||||
params![],
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue