melib/sqlite3: reset db on version mismatch
parent
54cb4ea623
commit
b9f4d718c7
|
@ -321,7 +321,7 @@ impl MailBackend for ImapType {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let mut state = FetchState {
|
let mut state = FetchState {
|
||||||
stage: if self.uid_store.keep_offline_cache {
|
stage: if self.uid_store.keep_offline_cache && cache_handle.is_some() {
|
||||||
FetchStage::InitialCache
|
FetchStage::InitialCache
|
||||||
} else {
|
} else {
|
||||||
FetchStage::InitialFresh
|
FetchStage::InitialFresh
|
||||||
|
|
|
@ -50,6 +50,8 @@ pub fn open_or_create_db(
|
||||||
description: &DatabaseDescription,
|
description: &DatabaseDescription,
|
||||||
identifier: Option<&str>,
|
identifier: Option<&str>,
|
||||||
) -> Result<Connection> {
|
) -> Result<Connection> {
|
||||||
|
let mut second_try: bool = false;
|
||||||
|
loop {
|
||||||
let db_path = if let Some(id) = identifier {
|
let db_path = if let Some(id) = identifier {
|
||||||
db_path(&format!("{}_{}", id, description.name))
|
db_path(&format!("{}_{}", id, description.name))
|
||||||
} else {
|
} else {
|
||||||
|
@ -79,11 +81,23 @@ pub fn open_or_create_db(
|
||||||
}
|
}
|
||||||
let version: i32 = conn.pragma_query_value(None, "user_version", |row| row.get(0))?;
|
let version: i32 = conn.pragma_query_value(None, "user_version", |row| row.get(0))?;
|
||||||
if version != 0_i32 && version as u32 != description.version {
|
if version != 0_i32 && version as u32 != description.version {
|
||||||
return Err(MeliError::new(format!(
|
log(
|
||||||
|
format!(
|
||||||
"Database version mismatch, is {} but expected {}",
|
"Database version mismatch, is {} but expected {}",
|
||||||
version, description.version
|
version, description.version
|
||||||
|
),
|
||||||
|
crate::INFO,
|
||||||
|
);
|
||||||
|
if second_try {
|
||||||
|
return Err(MeliError::new(format!(
|
||||||
|
"Database version mismatch, is {} but expected {}. Could not recreate database.",
|
||||||
|
version, description.version
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
reset_db(description, identifier)?;
|
||||||
|
second_try = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if version == 0 {
|
if version == 0 {
|
||||||
conn.pragma_update(None, "user_version", &description.version)?;
|
conn.pragma_update(None, "user_version", &description.version)?;
|
||||||
|
@ -93,7 +107,8 @@ pub fn open_or_create_db(
|
||||||
.map_err(|e| MeliError::new(e.to_string()))?;
|
.map_err(|e| MeliError::new(e.to_string()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(conn)
|
return Ok(conn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return database to a clean slate.
|
/// Return database to a clean slate.
|
||||||
|
|
Loading…
Reference in New Issue