Skip to content

Commit

Permalink
indexeddb: Add missing do_schema_upgrade call from v11 migration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richvdh committed Aug 7, 2024
1 parent 21efd60 commit 5dbee9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 5dbee9e

Please sign in to comment.