Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data Versioning - Multiple mapping models required

I have an existing project that uses Core Data, and I have 3 versions within my xcdatamodeld bundle. So far I have only used lightweight migration as I have mostly added new parameters and entities, however I now wish to move an existing parameter into a new entity. I realise that I have to crete a mapping model to do this in order to get the data migrated between the parameters.

I presume there are users out there with very old versions of the app using version 1 of the model, and others using version 2 and 3.

Questions:

  1. Do I need to create a mapping model from all existing versions to the new version, or just from the latest version
  2. Do I need to change/disable the lightweight migration options on my NSPersistentStoreCoordinator? Currently I have the following options enabled:

    NSMigratePersistentStoresAutomaticallyOption
    NSInferMappingModelAutomaticallyOption

I presume that lightweight migration will still be required to move from v1 to v2 to v3, however the new mapping model is required to go from v3 to v4. I've had a look around, but I can't find any information on how this all happens as most tutorials only cover 2 versions.

Thanks

like image 229
Craig Watkinson Avatar asked Nov 13 '22 16:11

Craig Watkinson


1 Answers

  1. Just from the latest version.
  2. No.

Migrations are sequential (which is the reason why you need to keep all model versions present, even if no migration from the first version is anticipated.

The NSMigratePersistentStoresAutomaticallyOption will only do the automatic migration if no mapping model is present.

like image 190
Mundi Avatar answered Nov 15 '22 05:11

Mundi