{"id":8854,"date":"2014-05-21T15:39:10","date_gmt":"2014-05-21T19:39:10","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=8854"},"modified":"2014-07-31T19:25:02","modified_gmt":"2014-07-31T23:25:02","slug":"problems-with-core-data-migration-manager-and-journal_mode-wal","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/05\/21\/problems-with-core-data-migration-manager-and-journal_mode-wal\/","title":{"rendered":"Problems With Core Data Migration Manager and Journal_mode WAL"},"content":{"rendered":"<p><a href=\"http:\/\/pablin.org\/2013\/05\/24\/problems-with-core-data-migration-manager-and-journal-mode-wal\/\">Pablo Bendersky<\/a>:<\/p>\r\n<blockquote cite=\"http:\/\/pablin.org\/2013\/05\/24\/problems-with-core-data-migration-manager-and-journal-mode-wal\/\"><p>When you use a <a href=\"http:\/\/developer.apple.com\/library\/ios\/#documentation\/cocoa\/conceptual\/CoreDataVersioning\/Articles\/vmLightweightMigration.html#\/\/apple_ref\/doc\/uid\/TP40004399-CH4-SW3\">Migration Manager<\/a>, Core Data will create a new database for you,\r\nand start copying the entities one by one from the old DB to the new one.<\/p>\r\n<p>As we are using <code>journal_mode = WAL<\/code>, there&rsquo;s an additional file besides <code>DB.sqlite<\/code> called <code>DB.sqlite-wal<\/code>.<\/p>\r\n<p>From what I can tell, the problem seems to be that Core Data creates a temporary DB, inserts everything\r\nthere, and when it renames it to the original name, the <code>-wal<\/code> file is kept as a leftover from the old\r\nversion. The problem is that you end up with an inconsistent DB.<\/p><\/blockquote>\r\n<p>A <a href=\"https:\/\/developer.apple.com\/library\/mac\/qa\/qa1809\/_index.html\">different part of Core Data<\/a> is aware of the multiple files, though:<\/p>\r\n<blockquote cite=\"https:\/\/developer.apple.com\/library\/mac\/qa\/qa1809\/_index.html\"><p>To safely back up and restore a Core Data SQLite store, you can do the following:<\/p>\r\n<ul>\r\n<li><p>Use the following method of <code>NSPersistentStoreCoordinator<\/code> class, rather than file system APIs, to back up and restore the Core Data store:<\/p><p><code> - (NSPersistentStore *)migratePersistentStore:(NSPersistentStore *)store toURL:(NSURL *)URL options:(NSDictionary *)options withType:(NSString *)storeType error:(NSError **)error <\/code><\/p><p>Note that this is the option we recommend.<\/p><\/li>\r\n<li><p>Change to rollback journaling mode when adding the store to a persistent store coordinator if you have to copy the store file.<\/p><\/li><\/ul><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Pablo Bendersky: When you use a Migration Manager, Core Data will create a new database for you, and start copying the entities one by one from the old DB to the new one. As we are using journal_mode = WAL, there&rsquo;s an additional file besides DB.sqlite called DB.sqlite-wal. From what I can tell, the problem [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[131,69,109,31,30,71,425],"class_list":["post-8854","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bug","tag-cocoa","tag-coredata","tag-ios","tag-mac","tag-programming","tag-sqlite"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=8854"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8854\/revisions"}],"predecessor-version":[{"id":9269,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8854\/revisions\/9269"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=8854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=8854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=8854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}