-
Notifications
You must be signed in to change notification settings - Fork 78
Add emulator state migration guide #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| --- | ||
| title: Migrating Emulator state to Cadence 1.0 | ||
| description: How to locally test storage migration and staged contract upgrades on Emulator | ||
| sidebar_position: 6 | ||
| --- | ||
|
|
||
| Flow CLI provides a command `flow migrate state` to migrate your local emulator | ||
| state to Cadence 1.0, and to deploy upgraded contracts to the emulator. | ||
| This is useful for locally testing the staged contract upgrades, and to see how the | ||
| new network and the upgraded contracts would behave with the migrated data. | ||
|
|
||
| ## Migration Guide | ||
|
|
||
| To test the migration, first you would need an emulator state, created with an emulator/CLI release | ||
| that uses a pre-1.0 Cadence version. | ||
|
|
||
| ### Getting the old state | ||
|
|
||
| It is recommended to use the latest pre-1.0 CLI version (e.g: `v1.14.*`) for creating the old state. | ||
| This is because the emulator shipped with older CLI versions may not include some of the system contracts | ||
| (e.g: `RandomBeaconHistory` contract) that are included by default in the newer versions of the emulator/CLI. | ||
| Such contracts are required for the migration. | ||
|
|
||
| **To get an emulator state with Flow CLI `1.14.0`:** | ||
|
|
||
| - Start the emulator with the `--persist` flag. | ||
| ```shell | ||
| flow emulator --persist | ||
| ``` | ||
|
|
||
| - Deploy the pre-1.0 project/contracts to the emulator | ||
| - Run transactions if there are any. | ||
| - Stop the emulator (Ctrl-C on *nix platforms, and Ctrl-Break or Ctrl-Pause on Windows). | ||
| **It is important to make sure the emulator is stopped before taking the snapshot, | ||
| so that any pending in-memory data would be written to the persisted state properly.** | ||
| - Locate the persisted state `./flowdb/emulator.sqlite` file, from the project root. | ||
|
|
||
| ### Migrating the state | ||
|
|
||
| Download and install the latest CLI, that runs Cadence 1.0. | ||
SupunS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - Run `flow-c1 migrate` against the previously created state. | ||
|
|
||
| - The state file (`emulator.sqlite`) can be provided using the `--db-path` flag. | ||
|
|
||
| - If there are any contracts that also need to be upgraded, those can be specified using the `--contracts` flag. | ||
| **Note that, the paths to these updated contracts and their deployed addresses must be specified in the `flow.json` file.** | ||
| For example, assuming the contract was deployed in the `test` account in the emulator, | ||
| and assuming the updated contract is in the `./updated_test_contract.cdc` file, the `flow.json` should include: | ||
| ```json | ||
| { | ||
| "contracts": { | ||
| "Test": "./updated_test_contract.cdc" | ||
| }, | ||
| "deployments": { | ||
| "emulator": { | ||
| "test": [ | ||
| "Test" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| - The migration will produce a report consisting of the migration status. | ||
| This can be enabled by setting the `--save-report` flag. | ||
|
|
||
| A sample `migrate` command would look like: | ||
|
|
||
| ```shell | ||
| flow-c1 migrate state --db-path=/path/to/emulator.sqlite --save-report=./reports --contracts="Test" | ||
| ``` | ||
|
|
||
| ### Testing the migrated state | ||
|
|
||
| Once the migration completes successfully, the emulator can be started with the migrated state. | ||
| For that, ensure the emulator is started again using the new CLI version (that runs Cadence 1.0), | ||
| with the `--persist` flag. | ||
| Now the emulator should be up and running using the migrated state and the updated contracts. | ||
| Run any transactions to verify the correctness of the existing data. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.