iPhone - core data migration
I have an app that has at least 300 entries. Each entry represent an object that may be free or in-app purchase. The app is on sale and it comes with a pre-filled sqlite file on the bundle. When the app runs for the first time, it checks to see if the database is there. If not it copies the sqlite file from the bundle to the app's directory and the magic starts.
As time passes and the user buys some in-app object, the database changes to mark those entries purchased.
Now I am about to release a new version. This new version comes with another sqlite file representing the objects. The stru开发者_如何学JAVActure is the same, but the new sqlite file representing the new database has now more objects.
I have read the docs and I am not finding an example that matches what I need to do, so I ask you guys. Which steps should I follow? I need to replace the current database (version 1) the user has with the new one (version 2), but while I do this, I need version 2 to have all changes version 1 has, since it was installed (in other words, copy the entities' properties that contains informations about the purchases.
How do I do that? Is this versioning? Migration?
thanks.
If the structure of the two data stores hasn't changed (the Managed Object Models are the same) then it's not versioning/migration. I'd say the easiest thing to do would be to check for the presence of the new objects in the database, and add them if they're not there.
Another alternative is to use both sqlite stores at the same time with mergedModelFromBundles
. I don't know much about that, and it might be more trouble than just creating the new objects in code and adding them.
精彩评论