diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/mod.rs b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/mod.rs index e542d35d7..e2dac253f 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/mod.rs @@ -176,9 +176,20 @@ async fn db_version(name: &str) -> Result { type OldVersion = u32; +/// Run a database schema upgrade operation +/// +/// # Arguments +/// +/// * `name` - name of the indexeddb database to be upgraded. +/// * `version` - version we are upgrading to. +/// * `f` - closure which will be called if the database is below the version +/// given. It will be called with three arguments `(db, txn, oldver)`, where: +/// * `db` - the [`IdbDatabase`] +/// * `txn` - the database transaction: a [`IdbTransaction`] +/// * `oldver` - the version number before the upgrade. async fn do_schema_upgrade(name: &str, version: u32, f: F) -> Result<(), DomException> where - F: Fn(&IdbDatabase, OldVersion) -> Result<(), JsValue> + 'static, + F: Fn(&IdbDatabase, IdbTransaction<'_>, OldVersion) -> Result<(), JsValue> + 'static, { info!("IndexeddbCryptoStore upgrade schema -> v{version} starting"); let mut db_req: OpenDbRequest = IdbDatabase::open_u32(name, version)?; @@ -190,7 +201,7 @@ where let old_version = evt.old_version() as u32; // Run the upgrade code we were supplied - f(evt.db(), old_version) + f(evt.db(), evt.transaction(), old_version) })); let db = db_req.await?; diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v0_to_v5.rs b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v0_to_v5.rs index 0800b7e14..75b1dc698 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v0_to_v5.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v0_to_v5.rs @@ -26,7 +26,7 @@ use crate::crypto_store::{ /// Perform schema migrations as needed, up to schema version 5. pub(crate) async fn schema_add(name: &str) -> Result<(), DomException> { - do_schema_upgrade(name, 5, |db, old_version| { + do_schema_upgrade(name, 5, |db, _, old_version| { // An old_version of 1 could either mean actually the first version of the // schema, or a completely empty schema that has been created with a // call to `IdbDatabase::open` with no explicit "version". So, to determine diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v10_to_v11.rs b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v10_to_v11.rs index 042b22138..11de8b32a 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v10_to_v11.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v10_to_v11.rs @@ -57,5 +57,5 @@ pub(crate) async fn data_migrate( pub(crate) async fn schema_bump(name: &str) -> crate::crypto_store::Result<(), DomException> { // Just bump the version number to 11 to demonstrate that we have run the data // changes from data_migrate. - do_schema_upgrade(name, 11, |_, _| Ok(())).await + do_schema_upgrade(name, 11, |_, _, _| Ok(())).await } diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v5_to_v7.rs b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v5_to_v7.rs index ea2ffc7e7..473960b3f 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v5_to_v7.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v5_to_v7.rs @@ -36,7 +36,7 @@ use crate::{ /// Perform the schema upgrade v5 to v6, creating `inbound_group_sessions2`. pub(crate) async fn schema_add(name: &str) -> Result<(), DomException> { - do_schema_upgrade(name, 6, |db, _| { + do_schema_upgrade(name, 6, |db, _, _| { let object_store = db.create_object_store(old_keys::INBOUND_GROUP_SESSIONS_V2)?; add_nonunique_index( @@ -109,7 +109,7 @@ pub(crate) async fn data_migrate(name: &str, serializer: &IndexeddbSerializer) - /// Perform the schema upgrade v6 to v7, deleting `inbound_group_sessions`. pub(crate) async fn schema_delete(name: &str) -> Result<(), DomException> { - do_schema_upgrade(name, 7, |db, _| { + do_schema_upgrade(name, 7, |db, _, _| { db.delete_object_store(old_keys::INBOUND_GROUP_SESSIONS_V1)?; Ok(()) }) diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v7_to_v8.rs b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v7_to_v8.rs index efa43c347..9cba57a7b 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v7_to_v8.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v7_to_v8.rs @@ -113,7 +113,7 @@ pub(crate) async fn data_migrate(name: &str, serializer: &IndexeddbSerializer) - /// Perform the schema upgrade v7 to v8, Just bumping the schema version. pub(crate) async fn schema_bump(name: &str) -> Result<(), DomException> { - do_schema_upgrade(name, 8, |_, _| { + do_schema_upgrade(name, 8, |_, _, _| { // Just bump the version number to 8 to demonstrate that we have run the data // changes from prepare_data_for_v8. Ok(()) diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v8_to_v10.rs b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v8_to_v10.rs index a0127febb..e180b5649 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v8_to_v10.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/v8_to_v10.rs @@ -35,7 +35,7 @@ use crate::{ /// Perform the schema upgrade v8 to v9, creating `inbound_group_sessions3`. pub(crate) async fn schema_add(name: &str) -> Result<(), DomException> { - do_schema_upgrade(name, 9, |db, _| { + do_schema_upgrade(name, 9, |db, _, _| { let object_store = db.create_object_store(keys::INBOUND_GROUP_SESSIONS_V3)?; add_nonunique_index( @@ -128,7 +128,7 @@ pub(crate) async fn data_migrate(name: &str, serializer: &IndexeddbSerializer) - /// Perform the schema upgrade v8 to v10, deleting `inbound_group_sessions2`. pub(crate) async fn schema_delete(name: &str) -> Result<(), DomException> { - do_schema_upgrade(name, 10, |db, _| { + do_schema_upgrade(name, 10, |db, _, _| { db.delete_object_store(old_keys::INBOUND_GROUP_SESSIONS_V2)?; Ok(()) })