Skip to content

Commit 3e37f9d

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): expose current version and keys used in event cache store database
1 parent 2689e2d commit 3e37f9d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

crates/matrix-sdk-indexeddb/src/event_cache_store/migrations.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,26 @@ use thiserror::Error;
2020
use wasm_bindgen::JsValue;
2121
use web_sys::{DomException, IdbIndexParameters};
2222

23-
const CURRENT_DB_VERSION: Version = Version::V1;
23+
/// The current version and keys used in the database.
24+
pub mod current {
25+
use super::{v1, Version};
26+
27+
pub const VERSION: Version = Version::V1;
28+
pub use v1::keys;
29+
}
2430

2531
/// Opens a connection to the IndexedDB database and takes care of upgrading it
2632
/// if necessary.
2733
#[allow(unused)]
2834
pub async fn open_and_upgrade_db(name: &str) -> Result<IdbDatabase, DomException> {
29-
let mut request = IdbDatabase::open_u32(name, CURRENT_DB_VERSION as u32)?;
35+
let mut request = IdbDatabase::open_u32(name, current::VERSION as u32)?;
3036
request.set_on_upgrade_needed(Some(|event: &IdbVersionChangeEvent| -> Result<(), JsValue> {
3137
let mut version =
3238
Version::try_from(event.old_version() as u32).map_err(DomException::from)?;
33-
while version < CURRENT_DB_VERSION {
39+
while version < current::VERSION {
3440
version = match version.upgrade(event.db())? {
3541
Some(next) => next,
36-
None => CURRENT_DB_VERSION, /* No more upgrades to apply, jump forward! */
42+
None => current::VERSION, /* No more upgrades to apply, jump forward! */
3743
};
3844
}
3945
Ok(())

0 commit comments

Comments
 (0)