Database Reference
In-Depth Information
• Default values: Adding, removing, or changing the default value of an
attribute
In addition, the following changes to the properties of an entity will also not
change the hash of the entity:
• User info: Adding, removing, or changing the user info key/values
• Validation predicates: Adding, removing, or changing the validation rules
The general distinction between things that do and do not affect version
hashes is whether the changes impact the store schema. Details such as the
class name impact only the runtime, not the structure of the persistent data.
Mapping Models
If Core Data detects that an upgrade to the persistent store is needed, it looks
for these three files in the application bundle:
• The MOM that matches the hash from the persistent store
• The current MOM
• The mapping model for those two MOM objects
Assuming that all three files are located, Core Data will then migrate the data
in the persistent store from the old MOM to the new MOM. If Core Data cannot
locate a mapping model, it checks to see whether inferred migration is turned
on and attempts to do a lightweight migration. If inferred is not turned on or
if the migration is too complex for a lightweight migration, an error will occur.
Once the migration is complete, the stack (MOC, PS, and MOM) is fully initial-
ized, and the application continues. This, of course, is the happy path, and
there are several safeguards in place to allow the application developer to
control failures.
Is it of vital importance that the application developer test the migration as
completely as possible and that every error condition be checked during
development and testing. With the delay in application releases to the App
Store, it has never been more important to ensure that the migration performs
correctly every time.
3.6
Progressive Data Migration (An Academic Exercise)
We're going to wrap up this chapter with a final section that's primarily a
mental and academic exercise, one that demonstrates the flexibility available
when working with Core Data migrations. Since it is possible to insert custom
code at nearly every point in a migration, we can do some very interesting
things. Let's take a look at an example.
 
 
Search WWH ::




Custom Search