[TM-276] Safe UStore migrations (imperative approach)
Description
This MR implements a prototype of type-safe UStore
migration using an imperative approach.
Here, in order to implement migration, you supply code which transforms old version of 'UStore' to a new version. At type level we ensure that all fields which should be added or removed are added/removed, and only them.
Field removals are intentionally made explicit, although with this approach this could be done automatically if desired.
This approach is convenient when migrating from non-initial version because changes between versions are usually small. It's not convenient for the very first migration because there we should initialize the full storage and manually writing code which does that seems tedious; instead, I think I will add a function similar to mkUStore
which will produce initializing migration from UStore template value (this will be a very light version of !51 (closed)).
Also see an alternative approach in !51 (closed).
In next MRs:
- Use type-safe migration in existing examples of migration.
- A function similar to
mkUStore
which creates code to migrate to the given UStore rather than an UStore constant.
Related issue(s)
https://issues.serokell.io/issue/TM-276
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.