Search code examples
iosobjective-ccore-dataensembles

Ensembles and journal_mode="DELETE"


My current Core Data stack is configured with journal_mode="DELETE" as follow:

NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES,
                          NSInferMappingModelAutomaticallyOption: @YES,
                          NSSQLitePragmasOption: @{@"journal_mode": @"DELETE"}};
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
    // Handle error 
}

This code enforces the Core Data to create a single sqlite file (rather than 3 different files in the WAL mode), which makes my life easier when it comes to backup and restore the sqlite database to user's Dropbox. (I need to backup or restore only one file instead of three)

When I add Ensembles code, it seems to override the NSSQLitePragmasOption and remove my custom DELETE journal_mode. I can conclude that since right after adding Ensembles code, I can see three sqlite files generated instead of just one.

Is this a known requirement/behavior of Ensembles? Can Ensemble function correctly only on WAL journal mode, or can I configure it to use DELETE journal mode just as well?

Thanks in advance.


Solution

  • There is a persistentStoreOptions property that can be used to tell the CDEPersistentStoreEnsemble what options should be used to access the store. Just pass your options to that property when you create your ensemble object.