Im busy migrating non-stable storage data to stable storage on the same caninster. I already wiped my first canister by accident so I was wondering;
- can non-stable and stable storage co-exist on a canister?
- if not, how would i migrate the data the easiest way?
- if so would non-stable memory where the data is restored by
pre- post-upgrade
conflict with stable memory?
pub static NON_STABLE_DATA: RefCell<Data> = RefCell::new(Data::default());
pub static STABLE_DATA: RefCell<StableCell<Data, Memory>> = RefCell::new(
StableCell::init(
MEMORY_MANAGER.with(|m| m.borrow().get(MemoryId::new(0))),
Data::default(),
).expect("failed")
);
for the migration i had somehting like this
#[update]
pub fn migrate_to_stable() {
let data = NON_STABLE_DATA.with(|d| d.borrow().clone());
let _ = STABLE_DATA.with(|stable| {
stable.borrow_mut().set(data)
});
}