Skip to content

Commit

Permalink
Improve migration code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Dec 23, 2021
1 parent 6bbcc30 commit 608b4f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, Contra

// Remove the old map keys
for (k, _) in current.iter() {
signed_int_map.remove(deps.storage, IntKeyOld::<i8>::from(*k));
signed_int_map.remove(deps.storage, (*k).into());
}

// Save in new format
for (k, v) in current.iter() {
signed_int_map_new.save(deps.storage, *k, v)?;
for (k, v) in current.into_iter() {
signed_int_map_new.save(deps.storage, k, &v)?;
}

// Confirm old map is empty
Expand Down
11 changes: 5 additions & 6 deletions packages/storage-plus/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,19 +685,18 @@ mod test {

// remove old entries
for (k, _) in current.iter() {
SIGNED_ID_OLD.remove(&mut store, IntKeyOld::<i32>::from(*k));
SIGNED_ID_OLD.remove(&mut store, (*k).into());
}

// confirm map is empty
assert!(SIGNED_ID_OLD
.range(&store, None, None, Order::Ascending)
.collect::<StdResult<Vec<_>>>()
.unwrap()
.is_empty());
.next()
.is_none());

// save in new format
for (k, v) in current.iter() {
SIGNED_ID.save(&mut store, *k, v).unwrap();
for (k, v) in current.into_iter() {
SIGNED_ID.save(&mut store, k, &v).unwrap();
}

// obtain new keys
Expand Down

0 comments on commit 608b4f7

Please sign in to comment.