Skip to content

Persistence versionning and migrating #178

Answered by jmeistrich
olup asked this question in Q&A
Discussion options

You must be logged in to vote

The way we suggest to do it is: the local property in persistObservable has an adjustData property which you can use for migration (among other things like encryption). The load function runs between loading from storage and setting into the observable, so this will migrate old storage data into the new format you want the observable to use.

This is a way to do it by specifying a version number to be able to define migrations per version. Or you could do it more ad-hoc or per-property by changing property names and detecting the old names.

interface V1 {
    version: number;
    test1: string;
}
interface V2 {
    version: number;
    test2: string;
}
const obs = observable<V2>({ version: 2,

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@olup
Comment options

@jmeistrich
Comment options

Answer selected by olup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants