I had some state in a canister deployed to Sodium, and I ran this command to update the frontend code while maintaining the state: dfx canister --network ic install --all --mode upgrade. But my state seems to have been wiped.
States are not preserved across upgrades by default. In Motoko, you can use the stable keywords to specify which variables to preserve: https://sdk.dfinity.org/docs/language-guide/actors-async.html#_stable_and_flexible_variables. In Rust, you need to provide pre_upgrade and post_upgrade functions, see https://github.com/dfinity/cdk-rs/blob/master/examples/asset_storage/src/asset_storage_rs/lib.rs as an example.
I see, I don’t think the documentation mentioned that. The documentation makes it seems like an upgrade just reserves state automatically.
Thanks for catching this,@lastmjs. This is an oversight and should definitely be mentioned in the documentation for upgrading a canister!
Please feel free to log issues like this if the docs repo too.