From 5dbee9ee9f6fe4f9d34faf2e155adb9717636b83 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 7 Aug 2024 13:47:10 +0100 Subject: [PATCH] indexeddb: Add missing `do_schema_upgrade` call from v11 migration We weren't updating the database schema version immediately after the v10 -> v11 migration. This was fine in practice, because (a) for now, there is no v12 migration so we ended up setting the schema version immediately anyway; (b) the migration is idempotent. However, it's inconsistent with the other migrations and confusing, and is about to make my test fail, so let's clean it up. --- .../src/crypto_store/migrations/mod.rs | 1 + .../src/crypto_store/migrations/v10_to_v11.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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 e87e5db07e5..23ccda98202 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/migrations/mod.rs @@ -109,6 +109,7 @@ pub async fn open_and_upgrade_db( if old_version < 11 { v10_to_v11::data_migrate(name, serializer).await?; + v10_to_v11::schema_bump(name).await?; } // Open and return the DB (we know it's at the latest version) 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 7bb94ffd349..042b221384f 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 @@ -17,12 +17,12 @@ use indexed_db_futures::IdbQuerySource; use wasm_bindgen::JsValue; -use web_sys::IdbTransactionMode; +use web_sys::{DomException, IdbTransactionMode}; use crate::crypto_store::{ indexeddb_serializer::IndexeddbSerializer, keys, - migrations::{old_keys, MigrationDb}, + migrations::{do_schema_upgrade, old_keys, MigrationDb}, }; /// Migrate data from `backup_keys.backup_key_v1` to @@ -52,3 +52,10 @@ pub(crate) async fn data_migrate( store.delete(&JsValue::from_str(old_keys::BACKUP_KEY_V1))?.await?; Ok(()) } + +/// Perform the schema upgrade v10 to v11, just bumping the schema version. +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 +}