Question

CoreData:Data-Migration How to move subset of data from one data store to another one?

I have an recipe manager core data app which ships with a preloaded sqlite database in Resources/. This is moved by version 1.0 to SomeAppSupportAreaFolder/. Later versions have the same situation but may have additional recipes in the database. At first launch of the new version(if any new recipes are present), I have used two core data stacks. I have been moving the new recipes only from MOCnew to MOCappSupport using an ever increasing recipe.recipeID to locate the newer recipes and to avoid duplicates being added, and to avoid overwriting possible user edits in the old preloaded recipes.

I use: insertNewObjectForEntityForName:. and then copy the data to the clone object.

This has worked for me.

My question is can this movement of selected recipe data be moved from the new dataStore to the old dataStore in a more direct way. Could it be done directly with say, a custom migration/NSMigrationPolicy? Is my current approach faulty?

Many Thanks, Mark

Was it helpful?

Solution

Your current approach is a good one, and you should probably keep using it.

Core Data migration is something else entirely. It refers to migrating to a new version of the data model, not to a different persistent store file. If you change your data model in some future version, you'll need to consider migration. Often migration can be automatic, if your changes are minor. But it's a completely separate topic from copying data from one store file to another one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top