Skip to content

Commit

Permalink
indexeddb: Pass the db upgrade transaction into do_schema_upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam authored and richvdh committed Aug 16, 2024
1 parent fa6066b commit ebc94bc
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ type OldVersion = u32;

async fn do_schema_upgrade<F>(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)?;
Expand All @@ -190,7 +190,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?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -131,7 +131,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(())
})
Expand Down

0 comments on commit ebc94bc

Please sign in to comment.