{"action":"opened","number":242,"pull_request":{"url":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls/242","id":73587315,"html_url":"https://github.com/project-imas/encrypted-core-data/pull/242","diff_url":"https://github.com/project-imas/encrypted-core-data/pull/242.diff","patch_url":"https://github.com/project-imas/encrypted-core-data/pull/242.patch","issue_url":"https://api.github.com/repos/project-imas/encrypted-core-data/issues/242","number":242,"state":"open","locked":false,"title":"Enabling all kinds of migration","user":{"login":"AndrewMcDrew","id":12459106,"avatar_url":"https://avatars.githubusercontent.com/u/12459106?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewMcDrew","html_url":"https://github.com/AndrewMcDrew","followers_url":"https://api.github.com/users/AndrewMcDrew/followers","following_url":"https://api.github.com/users/AndrewMcDrew/following{/other_user}","gists_url":"https://api.github.com/users/AndrewMcDrew/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewMcDrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewMcDrew/subscriptions","organizations_url":"https://api.github.com/users/AndrewMcDrew/orgs","repos_url":"https://api.github.com/users/AndrewMcDrew/repos","events_url":"https://api.github.com/users/AndrewMcDrew/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewMcDrew/received_events","type":"User","site_admin":false},"body":"Hi.\r\n\r\nThis pull request enables Core Data migration. It makes it possible to make non-lightweight migrations, with mapping models and migration policies. The main idea behind it is taken from Apple's [Incremental Store Programming Guide](https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/IncrementalStorePG/ImplementationStrategy/ImplementationStrategy.html#//apple_ref/doc/uid/TP40010706-CH2-SW2). As a Note in that section states:\r\n\r\n> Note: `loadMetadata:` should ignore any potential skew between the store and the model in use by the coordinator; this skew is handled automatically later, by the persistent store coordinator. It is sufficient to set the `NSStoreModelVersionHashes` key’s value to the version hashes that were saved in the store metadata the last time the store was saved (if the store is new, you return the version hashes for the current model in use).\r\n\r\nAs far as I understand the process of migration proceeds in this way:\r\n\r\n1. `NSPersistentStoreCoordinator` is instantiated with some managed object model, which has it's hashes in the `entityVersionHashesByName` property.\r\n2. While connecting to the actual store this coordinator calls the `loadMetadata:` method.\r\n3. This method sets `NSPersistentStore`'s `metadata` property. A dictionary in this property must contain managed object model's hashes, used the last time with this store. This method do not perform any migrations on it's own, this is a responsibility of the persistent store coordinator.\r\n4. After the `loadMetadata:` method invoking the coordinator checks the `metadata` property. If it's hashes and hashes in this dictionary are different, it starts a migration.\r\n5. During this migration a whole new Core Data stack is set up. This stack includes a new instance of `NSPersistentStore` class. For this instance the situation looks like it is it's first launch, even though it's managed object model is a new one. During the migration all of the old managed objects retrieved from the old store, passed through migration rules (mapping model, either defined by developer or inferred automatically as a part of a lightweight migration), and inserted into a new stack. From the new stack's persistent store point of view this looks the same as a just new installation.\r\n\r\nSo the problem was in the migration code in the Encrypted Core Data's `loadMetadata` method. I removed it and this gave Core Data a possibility to follow it's procedure, including any kind of migration.\r\n\r\nAdditionally, I removed all of the code, that is related to the migration. Maybe it's to radical.\r\n\r\nThere is one more technical problem here. To make a migration work it is necessary to store that hashes properly in the `metadata` property. This property must be overriden due to `NSPersistentStore` doc, but `NSIncrementalStore` overrides it by itself, so that there is no need to do that. Unfortunately, it does it in some strange way. It looks like this: the persistent store properly retrieves it's hashes, set them to the `metadata` property, but after the setting there are a new hashes in that property! This is the reason why the migration doesn't start in this situation -- Core Data doesn't see a difference in hashes. So I've overriden the `metadata` property, to preserve the hashes and to keep everithing else in the metadata untouched. The latter is important, because this `NSIncrementalStore`'s setter additionally sets some internal keys and values in the dictionary. Without this info the migration doesn't start either. Currently this is Apple's bug as for me, so I plan to post a bug to them regarding this property behaviour and look what they will answer.\r\n\r\nAdditionally, I've noticed a lot of tests in the example project. I am sorry but I haven't appropriate knowledge regarding tests. In fact, I wasn't even able to ran this example project -- I've done all of the job in my project, in which ECD is added via Cocoapods. So I haven't touched tests.\r\n\r\nThe last problem -- I am not aware whether this custom migration in the `loadMetadata` method allowed migration from an unencrypted store to the encrypted one. If so -- this change brakes it. But I believe this is not necessary for all of the Encrypted Core Data users -- if for the first app's users their stores already encrypted, then main priority is to make the migration just for an encrypted store.\r\n\r\nThis change can be useful for such issues: #190, #14, #141, #83.","created_at":"2016-06-13T14:43:29Z","updated_at":"2016-06-13T14:43:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls/242/commits","review_comments_url":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls/242/comments","review_comment_url":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls/comments{/number}","comments_url":"https://api.github.com/repos/project-imas/encrypted-core-data/issues/242/comments","statuses_url":"https://api.github.com/repos/project-imas/encrypted-core-data/statuses/99c53bfbc3c4f1793eaf8ea3f166e1a055b378c9","head":{"label":"AndrewMcDrew:migrationRemoval","ref":"migrationRemoval","sha":"99c53bfbc3c4f1793eaf8ea3f166e1a055b378c9","user":{"login":"AndrewMcDrew","id":12459106,"avatar_url":"https://avatars.githubusercontent.com/u/12459106?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewMcDrew","html_url":"https://github.com/AndrewMcDrew","followers_url":"https://api.github.com/users/AndrewMcDrew/followers","following_url":"https://api.github.com/users/AndrewMcDrew/following{/other_user}","gists_url":"https://api.github.com/users/AndrewMcDrew/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewMcDrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewMcDrew/subscriptions","organizations_url":"https://api.github.com/users/AndrewMcDrew/orgs","repos_url":"https://api.github.com/users/AndrewMcDrew/repos","events_url":"https://api.github.com/users/AndrewMcDrew/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewMcDrew/received_events","type":"User","site_admin":false},"repo":{"id":37538186,"name":"encrypted-core-data","full_name":"AndrewMcDrew/encrypted-core-data","owner":{"login":"AndrewMcDrew","id":12459106,"avatar_url":"https://avatars.githubusercontent.com/u/12459106?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewMcDrew","html_url":"https://github.com/AndrewMcDrew","followers_url":"https://api.github.com/users/AndrewMcDrew/followers","following_url":"https://api.github.com/users/AndrewMcDrew/following{/other_user}","gists_url":"https://api.github.com/users/AndrewMcDrew/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewMcDrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewMcDrew/subscriptions","organizations_url":"https://api.github.com/users/AndrewMcDrew/orgs","repos_url":"https://api.github.com/users/AndrewMcDrew/repos","events_url":"https://api.github.com/users/AndrewMcDrew/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewMcDrew/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AndrewMcDrew/encrypted-core-data","description":"v2.0 - iOS Core Data encrypted SQLite store using SQLCipher","fork":true,"url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data","forks_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/forks","keys_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/teams","hooks_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/hooks","issue_events_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/issues/events{/number}","events_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/events","assignees_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/assignees{/user}","branches_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/branches{/branch}","tags_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/tags","blobs_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/git/refs{/sha}","trees_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/statuses/{sha}","languages_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/languages","stargazers_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/stargazers","contributors_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/contributors","subscribers_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/subscribers","subscription_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/subscription","commits_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/commits{/sha}","git_commits_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/git/commits{/sha}","comments_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/comments{/number}","issue_comment_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/issues/comments{/number}","contents_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/contents/{+path}","compare_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/merges","archive_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/downloads","issues_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/issues{/number}","pulls_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/pulls{/number}","milestones_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/milestones{/number}","notifications_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/labels{/name}","releases_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/releases{/id}","deployments_url":"https://api.github.com/repos/AndrewMcDrew/encrypted-core-data/deployments","created_at":"2015-06-16T15:18:19Z","updated_at":"2015-06-16T15:18:20Z","pushed_at":"2016-06-13T09:30:51Z","git_url":"git://github.com/AndrewMcDrew/encrypted-core-data.git","ssh_url":"git@github.com:AndrewMcDrew/encrypted-core-data.git","clone_url":"https://github.com/AndrewMcDrew/encrypted-core-data.git","svn_url":"https://github.com/AndrewMcDrew/encrypted-core-data","homepage":"","size":1030,"stargazers_count":0,"watchers_count":0,"language":"Objective-C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"project-imas:master","ref":"master","sha":"bc34ec48850a06c6f2f2714abcd6f3d7b98a9002","user":{"login":"project-imas","id":2981991,"avatar_url":"https://avatars.githubusercontent.com/u/2981991?v=3","gravatar_id":"","url":"https://api.github.com/users/project-imas","html_url":"https://github.com/project-imas","followers_url":"https://api.github.com/users/project-imas/followers","following_url":"https://api.github.com/users/project-imas/following{/other_user}","gists_url":"https://api.github.com/users/project-imas/gists{/gist_id}","starred_url":"https://api.github.com/users/project-imas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-imas/subscriptions","organizations_url":"https://api.github.com/users/project-imas/orgs","repos_url":"https://api.github.com/users/project-imas/repos","events_url":"https://api.github.com/users/project-imas/events{/privacy}","received_events_url":"https://api.github.com/users/project-imas/received_events","type":"Organization","site_admin":false},"repo":{"id":5601299,"name":"encrypted-core-data","full_name":"project-imas/encrypted-core-data","owner":{"login":"project-imas","id":2981991,"avatar_url":"https://avatars.githubusercontent.com/u/2981991?v=3","gravatar_id":"","url":"https://api.github.com/users/project-imas","html_url":"https://github.com/project-imas","followers_url":"https://api.github.com/users/project-imas/followers","following_url":"https://api.github.com/users/project-imas/following{/other_user}","gists_url":"https://api.github.com/users/project-imas/gists{/gist_id}","starred_url":"https://api.github.com/users/project-imas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-imas/subscriptions","organizations_url":"https://api.github.com/users/project-imas/orgs","repos_url":"https://api.github.com/users/project-imas/repos","events_url":"https://api.github.com/users/project-imas/events{/privacy}","received_events_url":"https://api.github.com/users/project-imas/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/project-imas/encrypted-core-data","description":"v2.0 - iOS Core Data encrypted SQLite store using SQLCipher","fork":false,"url":"https://api.github.com/repos/project-imas/encrypted-core-data","forks_url":"https://api.github.com/repos/project-imas/encrypted-core-data/forks","keys_url":"https://api.github.com/repos/project-imas/encrypted-core-data/keys{/key_id}","collaborators_url":"https://api.github.com/repos/project-imas/encrypted-core-data/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/project-imas/encrypted-core-data/teams","hooks_url":"https://api.github.com/repos/project-imas/encrypted-core-data/hooks","issue_events_url":"https://api.github.com/repos/project-imas/encrypted-core-data/issues/events{/number}","events_url":"https://api.github.com/repos/project-imas/encrypted-core-data/events","assignees_url":"https://api.github.com/repos/project-imas/encrypted-core-data/assignees{/user}","branches_url":"https://api.github.com/repos/project-imas/encrypted-core-data/branches{/branch}","tags_url":"https://api.github.com/repos/project-imas/encrypted-core-data/tags","blobs_url":"https://api.github.com/repos/project-imas/encrypted-core-data/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/project-imas/encrypted-core-data/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/project-imas/encrypted-core-data/git/refs{/sha}","trees_url":"https://api.github.com/repos/project-imas/encrypted-core-data/git/trees{/sha}","statuses_url":"https://api.github.com/repos/project-imas/encrypted-core-data/statuses/{sha}","languages_url":"https://api.github.com/repos/project-imas/encrypted-core-data/languages","stargazers_url":"https://api.github.com/repos/project-imas/encrypted-core-data/stargazers","contributors_url":"https://api.github.com/repos/project-imas/encrypted-core-data/contributors","subscribers_url":"https://api.github.com/repos/project-imas/encrypted-core-data/subscribers","subscription_url":"https://api.github.com/repos/project-imas/encrypted-core-data/subscription","commits_url":"https://api.github.com/repos/project-imas/encrypted-core-data/commits{/sha}","git_commits_url":"https://api.github.com/repos/project-imas/encrypted-core-data/git/commits{/sha}","comments_url":"https://api.github.com/repos/project-imas/encrypted-core-data/comments{/number}","issue_comment_url":"https://api.github.com/repos/project-imas/encrypted-core-data/issues/comments{/number}","contents_url":"https://api.github.com/repos/project-imas/encrypted-core-data/contents/{+path}","compare_url":"https://api.github.com/repos/project-imas/encrypted-core-data/compare/{base}...{head}","merges_url":"https://api.github.com/repos/project-imas/encrypted-core-data/merges","archive_url":"https://api.github.com/repos/project-imas/encrypted-core-data/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/project-imas/encrypted-core-data/downloads","issues_url":"https://api.github.com/repos/project-imas/encrypted-core-data/issues{/number}","pulls_url":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls{/number}","milestones_url":"https://api.github.com/repos/project-imas/encrypted-core-data/milestones{/number}","notifications_url":"https://api.github.com/repos/project-imas/encrypted-core-data/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/project-imas/encrypted-core-data/labels{/name}","releases_url":"https://api.github.com/repos/project-imas/encrypted-core-data/releases{/id}","deployments_url":"https://api.github.com/repos/project-imas/encrypted-core-data/deployments","created_at":"2012-08-29T14:02:22Z","updated_at":"2016-06-10T01:41:28Z","pushed_at":"2016-06-03T07:39:22Z","git_url":"git://github.com/project-imas/encrypted-core-data.git","ssh_url":"git@github.com:project-imas/encrypted-core-data.git","clone_url":"https://github.com/project-imas/encrypted-core-data.git","svn_url":"https://github.com/project-imas/encrypted-core-data","homepage":"","size":1353,"stargazers_count":559,"watchers_count":559,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":159,"mirror_url":null,"open_issues_count":29,"forks":159,"open_issues":29,"watchers":559,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls/242"},"html":{"href":"https://github.com/project-imas/encrypted-core-data/pull/242"},"issue":{"href":"https://api.github.com/repos/project-imas/encrypted-core-data/issues/242"},"comments":{"href":"https://api.github.com/repos/project-imas/encrypted-core-data/issues/242/comments"},"review_comments":{"href":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls/242/comments"},"review_comment":{"href":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/project-imas/encrypted-core-data/pulls/242/commits"},"statuses":{"href":"https://api.github.com/repos/project-imas/encrypted-core-data/statuses/99c53bfbc3c4f1793eaf8ea3f166e1a055b378c9"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":2,"additions":33,"deletions":438,"changed_files":2}}
{"actor":{"display_login":"AndrewMcDrew"}}