Error transferring basic information when transferring between endless versions

Problem

  • I have 13 versions of my underlying data model.
  • I created 13 matching models (V1-V2, V2-V3, etc.)
  • I have automatic migration enabled.
  • When migrating between two consecutive versions (e.g. V12-V13) the migration works fine
  • When migrating between two inconsistent versions (for example, V11-V13), the migration fails:

    Can't find mapping model for migration

What i tried

Create a display model for each possible combination of versions. It works, but it's a real hassle.

For version 14, I will need to make 14 different matching models. Manually. Ugh.

the code

Here are the parameters I pass in for the transfer:

 [persistentStoreCoordinator addPersistentStoreWithType:[self storeType] configuration:nil URL:url options:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:NO], NSReadOnlyPersistentStoreOption, nil] error:&error]){ 

Data model

My data model is pretty complicated, but here it is: http://dl.dropbox.com/u/136780/Engine_V2_DataModel.xcdatamodeld.zip

I do not use version hash modifiers or rename identifiers in my data model right now.

+6
source share
1 answer

See this question: Migrate master data when upgrading multiple versions

Basically, the bottom line is that you do not need to create a complete set of matching models. You just need matching models between each pair of consecutive models, and then you can gradually transfer any old model through intermediate models to the newest model.

Productivity may not be very good depending on your store, because you do not complete the migration in one step. However, this may be good enough, and it might be worth not creating a complete set of matching models. You can also test the effectiveness of this method to determine if you need to create maps between endless versions of your model.

Marcus Zarra (the main extraordinary data source) has the code here: http://media.pragprog.com/titles/mzcd/code/ProgressiveMigration/AppDelegate.m

(I was going to ask this question, but thanks to LazyTwitter, I pointed out this answer by Aaron Tuller: https://twitter.com/tullera/status/57708304683642880 )

+8
source

Source: https://habr.com/ru/post/885497/


All Articles