Database Reference
In-Depth Information
Now we need to loop back to step 1 again in our workflow. Therefore, we will
recursively call ourselves, returning the result of that recurse. As you can
recall from the beginning of this method, if we are now at the current version,
we will simply return YES , which will end the recursion.
RecipesV3/PPRecipes/PPRAppDelegate.m
NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString];
guid = [guid stringByAppendingPathExtension:modelName];
guid = [guid stringByAppendingPathExtension:storeExtension];
NSString *appSupportPath = [storePath stringByDeletingLastPathComponent];
NSString *backupPath = [appSupportPath stringByAppendingPathComponent:guid];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager moveItemAtPath:[sourceStoreURL path]
toPath:backupPath
error:error]) {
//Failed to copy the file
return NO;
}
//Move the destination to the source path
if (![fileManager moveItemAtPath:storePath
toPath:[sourceStoreURL path]
error:error]) {
//Try to back out the source move first, no point in checking it for errors
[fileManager moveItemAtPath:backupPath
toPath:[sourceStoreURL path]
error:nil];
return NO;
}
//We may not be at the "current" model yet, so recurse
return [self progressivelyMigrateURL:sourceStoreURL
ofType:type
toModel:finalModel
error:error];
This progressive migration can be tested by first running version 1 of our
Grokking Recipes application, entering some data, and then running the third
version. You will then see the data model migrate seamlessly from version 1
to version 3 with no intervention required.
3.7
Wrapping Up
We explored how to deal with changes and additions to our application and
discussed data migration. In the next chapter, we're going to take a look at
how our applications perform and ways to tune them.
 
 
 
Search WWH ::




Custom Search