Skip to content

What is the best practice for store migration #10

Answered by subdigital
runjuu asked this question in Q&A
Discussion options

You must be logged in to vote

I've done this extensively on an important project with success. It can work, but you have to plan out a strategy.

There are a couple of approaches you might consider. If your data needs to be migrated from older versions (i.e. you can't just blow away the cache and save again with fresh data from the server) then you need some sort of versioning scheme.

Option A: Versioning in the model

This requires you to store the version of a model in the model's Codable data, so you can intelligently reason about the data that is being hydrated from data.

Something like:

struct Widget: Codable {
    let createdAt: Date

    enum Version: String {
       case v1
       case v2 // changed date format …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by runjuu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants