Re: Core data migration question
Re: Core data migration question
- Subject: Re: Core data migration question
- From: mmalc Crawford <email@hidden>
- Date: Tue, 07 Apr 2009 14:09:51 -0700
On Apr 7, 2009, at 12:28 PM, Timothy Larkin wrote:
I think that Jon is asking whether he should give a version number
to his data model, and not whether he should create a second version
of his data model. If this is in fact his question, then I think the
answer is yes, because this will make it easier, if he needs to
migrate at some time in the future, to identify which data model
version he migrating from.
Again, no.
You don't need to specify a version number for the previous model,
Core Data ignores it:
<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmVersioning.html#//apple_ref/doc/uid/TP40004714
>
"As a developer, your perspective is typically that a version is
denoted by an identifier—a string or number, such as “9A218”, “2.0.7”,
or “Version 1.1”. [...]
Core Data, on the other hand, treats these identifiers simply as
“hints”."
In particular:
"Notice that Core Data ignores any identifiers you set. In the
examples above, Core Data treats version 1.0 (Figure 1) and 1.1
(Figure 2) as being compatible."
You typically don't need to retrieve the source model yourself:
"If your application does support versioning and you choose to use the
default migration process, you simply use
addPersistentStoreWithType:configuration:URL:options:error: as
described in “The Default Migration Process.” The fundamental
difference from the non-versioned approach is that you instruct the
coordinator to automatically migrate the store to the current model
version by adding an entry to the options dictionary where the key is
NSMigratePersistentStoresAutomaticallyOption and the value is an
NSNumberobject that represents YES."
<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmInitiating.html#//apple_ref/doc/uid/TP40005509
>
Even if you do want to initiate migration yourself, you ask Core Data
to find the source model:
NSManagedObjectModel *sourceModel =
[NSManagedObjectModel mergedModelFromBundles:bundlesForSourceModel
forStoreMetadata:sourceMetadata];
<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmCustomizingTheProcess.html#//apple_ref/doc/uid/TP40005510-SW4
>
mmalc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden