CoreData: How will you migrate an unversioned store?

So, I am working on a project that has been posted to users. Before I put my hand on this project, this project is version 1.0 and 2.0, v2.0 modified the master data data model, but whoever did it did not add the new version to the data model.

So when the user upgrades from 1.0 to 2.0, it will crash.

My problem is that I am deploying v3.0, how do I change my xcdatamodel so that a user from v1.0 and v2.0 can upgrade to v3.0 without problems?

+3


source to share


2 answers


Get a V1 model and add a new version to it that is identical to v2, and then add another V3 model to it so you get a model that has all three versions. Thus, you should be able to use light migration from any of the previous versions, assuming that your changes to the model will actually make the migration easier. If not, then do a manual migration as @Mundi suggests. You can restore the V1 model from the V1 app bundle if you no longer have the source code but you need a copy of the V1 app bundle to do so. You may have to google how to do this or let me know and I'll hunt as I will document somewhere ... Hope this helps.



+2


source


The only possible solution that comes to mind seems to be to include two data models in the model. (Basically, a version control system does something similar.)

Read the data with the first model, then "manually" copy it to the data store of the second model (modify it if necessary). From now on, only use the second model (which should be a version for future changes).



I would block the UI and post like "migrating your data" to make sure the user interaction is not interfering with this process.

0


source







All Articles