简体   繁体   中英

core data versioning on document based applications

My application uses Core-data. Now, with the release of the new version I need to change the database structure. I know this is done via versioning, but all I have found, all tutorials are not for document based applications and at some point i get stuck. How can Versioning be implemented on a document based application, where the document is the database itself and can have any name?

Thanks

---Additional info----

what i would need to do is: open the application, hit the "open" button, select the NSManagedDocument from the filesystem. that is my database (can have any name) if on opening it detects that it is an old structure it should update its structure to the current one. (one column added)

It seems to me that the fact that you are wrapping the SQLite store into an NSManagedDocument is irrelevant to the model versioning procedure.

Just proceed by adding the persistent store options in code and the new model version in Xcode.

When setting up your core data stack - ie after the document with the DB has been chosen - you have to add these options to the persistent store when creating the persistent store coordinator:

NSString * const NSMigratePersistentStoresAutomaticallyOption;
NSString * const NSInferMappingModelAutomaticallyOption;

As the names of these options imply, it should work automatically from here. The actual call would look something like this:

[persistentStoreCoordinator 
   addPersistentStoreWithType:NSSQLiteStoreType
   configuration:@"Default"
   URL:fileURL 
   options:@{NSMigratePersistentStoresAutomaticallyOption : @(YES),
             NSInferMappingModelAutomaticallyOption       : @(YES)}
   error:&error];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM