Skip to content
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

Incremental migrations support #25

Open
hashedone opened this issue Aug 25, 2022 · 0 comments
Open

Incremental migrations support #25

hashedone opened this issue Aug 25, 2022 · 0 comments
Assignees
Labels

Comments

@hashedone
Copy link
Collaborator

hashedone commented Aug 25, 2022

Build on #17

The problem with migrations is their incremental structure. Having contract version 1.0, adding a migrate entry point to update to 1.1 is simple - just update the state. The problem started with the release of 1.2 with some more state changes requiring another migration - and now the contract should be able to migrate from both 1.0, and 1.1 versions. And the problem grows with time.

The idea is to be able to define migrations as simple steps, like 1.0 -> 1.1, 1.1 -> 1.2, and then the final migrate function based on the version of the on-chain contract figures out what steps are required to take to update the contract.

The concept looks like this:

struct Contract { /* ... */ }

#[contract]
impl Contract {
  #[msg(migrate, from = 1.0, to = 1.1)]
  fn migrate1_0(&self, ctx: MigrationCtx, /* ... */)  -> Result<Respons, ContractError> {
    /* ... */
  }

  #[msg(migrate, from = 1.1, to = 1.2)]
  fn migrate1_1(&self, ctx: MigrationCtx, /* ... */)  -> Result<Respons, ContractError> {
    /* ... */
  }
}

Now Sylvia should be able to generate paths to update from all the versions (1.0 and 1.1), then just match on the version of the on-chain contract, and call proper migrations (updating versions).

Additionally, there should be at least a warning (probably even an error) if there is any migration method in the contract, but none of them has "to" equal to the current contract version. Or even stronger - if there is any version with no migration path to the current contract version. It should be detectable by Sylvia and rise in compile time (panicking in constant context). The reason is, that it is very easy to forget about migration. If it is on purpose there may be two cases:

  • Abandoning support for migration from older versions - in such a case, such migrations should be removed from code as they are not needed anymore
  • State of the contract didn't change since the last version - in such a case, you can just change "to" of the latest migration.

For contract versioning, it is preferred to use the https://crates.io/crates/cw2 crate - instantiate entry point should have generated storing the contract name (being crate name) and contract version (using crate version in cargo). Then migrate should check this info and update it after successful migration.

@hashedone hashedone added the idea label Aug 25, 2022
@hashedone hashedone added this to the 0.4 milestone Jan 10, 2023
@hashedone hashedone modified the milestones: 0.4, 0.5 Apr 28, 2023
@jawoznia jawoznia added backlog Items planned to be done, but with no milestone yet and removed idea labels Mar 19, 2024
@jawoznia jawoznia removed this from the 0.5 milestone Mar 19, 2024
@jawoznia jawoznia added idea and removed backlog Items planned to be done, but with no milestone yet labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants