{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-java/pulls/comments/65502083","id":65502083,"diff_hunk":"@@ -204,6 +204,14 @@ public RealmObjectSchema removeField(String fieldName) {\n         if (table.getPrimaryKey() == columnIndex) {\n             table.setPrimaryKey(null);\n         }\n+        // When PK does not exist (-2) this cannot happen. Meanwhile a removal target has a smaller\n+        // index than the PK index, we can expect an rearrangement.\n+        if (columnIndex < table.getPrimaryKey()) {\n+            String pkField = getPrimaryKey();\n+            table.removeColumn(columnIndex);\n+            table.setPrimaryKey(pkField);\n+            return this;\n+        }\n         table.removeColumn(columnIndex);","path":"realm/realm-library/src/main/java/io/realm/RealmObjectSchema.java","position":12,"original_position":12,"commit_id":"bc3640b9ab07027caff53afc1cfe896d662f70d8","original_commit_id":"bc3640b9ab07027caff53afc1cfe896d662f70d8","user":{"login":"stk1m1","id":16395854,"avatar_url":"https://avatars.githubusercontent.com/u/16395854?v=3","gravatar_id":"","url":"https://api.github.com/users/stk1m1","html_url":"https://github.com/stk1m1","followers_url":"https://api.github.com/users/stk1m1/followers","following_url":"https://api.github.com/users/stk1m1/following{/other_user}","gists_url":"https://api.github.com/users/stk1m1/gists{/gist_id}","starred_url":"https://api.github.com/users/stk1m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stk1m1/subscriptions","organizations_url":"https://api.github.com/users/stk1m1/orgs","repos_url":"https://api.github.com/users/stk1m1/repos","events_url":"https://api.github.com/users/stk1m1/events{/privacy}","received_events_url":"https://api.github.com/users/stk1m1/received_events","type":"User","site_admin":false},"body":"Uh, not really. A column will only be removed once. You can see it in [my comment](https://github.com/realm/realm-java/pull/2920/files#r65501958)","created_at":"2016-06-02T08:29:44Z","updated_at":"2016-06-02T08:29:44Z","html_url":"https://github.com/realm/realm-java/pull/2920#discussion_r65502083","pull_request_url":"https://api.github.com/repos/realm/realm-java/pulls/2920","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments/65502083"},"html":{"href":"https://github.com/realm/realm-java/pull/2920#discussion_r65502083"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2920"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-java/pulls/2920","id":72172815,"html_url":"https://github.com/realm/realm-java/pull/2920","diff_url":"https://github.com/realm/realm-java/pull/2920.diff","patch_url":"https://github.com/realm/realm-java/pull/2920.patch","issue_url":"https://api.github.com/repos/realm/realm-java/issues/2920","number":2920,"state":"open","locked":false,"title":" PrimaryKey index rearrangement in migration revisited ","user":{"login":"stk1m1","id":16395854,"avatar_url":"https://avatars.githubusercontent.com/u/16395854?v=3","gravatar_id":"","url":"https://api.github.com/users/stk1m1","html_url":"https://github.com/stk1m1","followers_url":"https://api.github.com/users/stk1m1/followers","following_url":"https://api.github.com/users/stk1m1/following{/other_user}","gists_url":"https://api.github.com/users/stk1m1/gists{/gist_id}","starred_url":"https://api.github.com/users/stk1m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stk1m1/subscriptions","organizations_url":"https://api.github.com/users/stk1m1/orgs","repos_url":"https://api.github.com/users/stk1m1/repos","events_url":"https://api.github.com/users/stk1m1/events{/privacy}","received_events_url":"https://api.github.com/users/stk1m1/received_events","type":"User","site_admin":false},"body":"This PR fixes followings. \r\n\r\n1. When a column with a smaller index than that of a primary key field gets removed, the primary key field index decrements, which causes a cached primary key index to point a wrong field. \r\n\r\n2. When a primary key field is renamed, primary key table is not updated accordingly.\r\n\r\nCloses #2829. \r\n\r\n@realm/java please review.","created_at":"2016-06-01T12:37:08Z","updated_at":"2016-06-02T08:29:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e5aa3efee11ca42a6b8957c4a2272369b9df5df","assignee":{"login":"stk1m1","id":16395854,"avatar_url":"https://avatars.githubusercontent.com/u/16395854?v=3","gravatar_id":"","url":"https://api.github.com/users/stk1m1","html_url":"https://github.com/stk1m1","followers_url":"https://api.github.com/users/stk1m1/followers","following_url":"https://api.github.com/users/stk1m1/following{/other_user}","gists_url":"https://api.github.com/users/stk1m1/gists{/gist_id}","starred_url":"https://api.github.com/users/stk1m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stk1m1/subscriptions","organizations_url":"https://api.github.com/users/stk1m1/orgs","repos_url":"https://api.github.com/users/stk1m1/repos","events_url":"https://api.github.com/users/stk1m1/events{/privacy}","received_events_url":"https://api.github.com/users/stk1m1/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-java/pulls/2920/commits","review_comments_url":"https://api.github.com/repos/realm/realm-java/pulls/2920/comments","review_comment_url":"https://api.github.com/repos/realm/realm-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/2920/comments","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/bc3640b9ab07027caff53afc1cfe896d662f70d8","head":{"label":"realm:stk/bug/migratingpk","ref":"stk/bug/migratingpk","sha":"bc3640b9ab07027caff53afc1cfe896d662f70d8","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4084908,"name":"realm-java","full_name":"realm/realm-java","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-java","description":"Realm is a mobile database: a replacement for SQLite & ORMs","fork":false,"url":"https://api.github.com/repos/realm/realm-java","forks_url":"https://api.github.com/repos/realm/realm-java/forks","keys_url":"https://api.github.com/repos/realm/realm-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-java/teams","hooks_url":"https://api.github.com/repos/realm/realm-java/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-java/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-java/events","assignees_url":"https://api.github.com/repos/realm/realm-java/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-java/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-java/tags","blobs_url":"https://api.github.com/repos/realm/realm-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-java/languages","stargazers_url":"https://api.github.com/repos/realm/realm-java/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-java/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-java/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-java/subscription","commits_url":"https://api.github.com/repos/realm/realm-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-java/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-java/merges","archive_url":"https://api.github.com/repos/realm/realm-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-java/downloads","issues_url":"https://api.github.com/repos/realm/realm-java/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-java/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-java/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-java/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-java/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-java/deployments","created_at":"2012-04-20T09:18:42Z","updated_at":"2016-06-02T08:27:46Z","pushed_at":"2016-06-02T08:18:32Z","git_url":"git://github.com/realm/realm-java.git","ssh_url":"git@github.com:realm/realm-java.git","clone_url":"https://github.com/realm/realm-java.git","svn_url":"https://github.com/realm/realm-java","homepage":"http://realm.io","size":61967,"stargazers_count":5076,"watchers_count":5076,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":666,"mirror_url":null,"open_issues_count":235,"forks":666,"open_issues":235,"watchers":5076,"default_branch":"master"}},"base":{"label":"realm:releases","ref":"releases","sha":"6d7e9b0bf108efc3e95c8d23b2676c9aba1dc78b","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4084908,"name":"realm-java","full_name":"realm/realm-java","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-java","description":"Realm is a mobile database: a replacement for SQLite & ORMs","fork":false,"url":"https://api.github.com/repos/realm/realm-java","forks_url":"https://api.github.com/repos/realm/realm-java/forks","keys_url":"https://api.github.com/repos/realm/realm-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-java/teams","hooks_url":"https://api.github.com/repos/realm/realm-java/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-java/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-java/events","assignees_url":"https://api.github.com/repos/realm/realm-java/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-java/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-java/tags","blobs_url":"https://api.github.com/repos/realm/realm-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-java/languages","stargazers_url":"https://api.github.com/repos/realm/realm-java/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-java/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-java/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-java/subscription","commits_url":"https://api.github.com/repos/realm/realm-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-java/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-java/merges","archive_url":"https://api.github.com/repos/realm/realm-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-java/downloads","issues_url":"https://api.github.com/repos/realm/realm-java/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-java/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-java/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-java/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-java/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-java/deployments","created_at":"2012-04-20T09:18:42Z","updated_at":"2016-06-02T08:27:46Z","pushed_at":"2016-06-02T08:18:32Z","git_url":"git://github.com/realm/realm-java.git","ssh_url":"git@github.com:realm/realm-java.git","clone_url":"https://github.com/realm/realm-java.git","svn_url":"https://github.com/realm/realm-java","homepage":"http://realm.io","size":61967,"stargazers_count":5076,"watchers_count":5076,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":666,"mirror_url":null,"open_issues_count":235,"forks":666,"open_issues":235,"watchers":5076,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2920"},"html":{"href":"https://github.com/realm/realm-java/pull/2920"},"issue":{"href":"https://api.github.com/repos/realm/realm-java/issues/2920"},"comments":{"href":"https://api.github.com/repos/realm/realm-java/issues/2920/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2920/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2920/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-java/statuses/bc3640b9ab07027caff53afc1cfe896d662f70d8"}}}}
{"actor":{"display_login":"stk1m1"}}