Skip to content

Commit

Permalink
change version check and add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Sep 15, 2024
1 parent df164d4 commit a5c612c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 7 additions & 1 deletion mm2src/coins/nft/storage/wasm/wasm_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use num_traits::ToPrimitive;
use serde_json::{self as json, Value as Json};
use std::collections::HashSet;
use std::num::NonZeroUsize;
use wasm_bindgen::JsValue;
use web_sys::console;

const CHAIN_TOKEN_ADD_TOKEN_ID_INDEX: &str = "chain_token_add_token_id_index";
const CHAIN_BLOCK_NUMBER_INDEX: &str = "chain_block_number_index";
Expand Down Expand Up @@ -1012,9 +1014,11 @@ impl TableSignature for NftTransferHistoryTable {
table.create_multi_index(CHAIN_IMAGE_DOMAIN_INDEX, &["chain", "image_domain"], false)?;
table.create_index("block_number", false)?;
table.create_index("chain", false)?;
} else if old_version == 1 && new_version == 2 {
} else if new_version == 2 {
// Migration from version 1 to version 2

console::log_1(&JsValue::from_str("Migrating from version 1 to version 2."));

// Step 1: Create a temporary table to hold data with the old schema
let temp_table_name = format!("{}_temp", Self::TABLE_NAME);
let temp_table = upgrader.create_table(&temp_table_name)?;
Expand Down Expand Up @@ -1042,6 +1046,8 @@ impl TableSignature for NftTransferHistoryTable {
// TODO copy data from old_store to temp_store
copy_store_data_sync(&old_store.object_store, &temp_store.object_store)?;

console::log_1(&JsValue::from_str("Copied data from old store to temp store"));

// Step 3: Delete the old object store
upgrader.delete_table(Self::TABLE_NAME)?;

Expand Down
3 changes: 0 additions & 3 deletions mm2src/mm2_db/src/indexed_db/drivers/upgrader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,5 @@ pub fn copy_store_data_sync(
// Prevent the closure from being dropped
onsuccess_callback.forget();

// Note: We cannot block the function here to wait for completion.
// The transaction will remain open until all requests are completed.

Ok(())
}

0 comments on commit a5c612c

Please sign in to comment.