{"action":"created","comment":{"url":"https://api.github.com/repos/thoughtbot/hound/pulls/comments/25743628","id":25743628,"diff_hunk":"@@ -0,0 +1,26 @@\n+class AddUniqueConstraintToMemberships < ActiveRecord::Migration\n+  def self.up\n+    remove_duplicate_memberships\n+\n+    add_index :memberships, [:user_id, :repo_id], unique: true\n+    remove_index :memberships, column: :user_id\n+  end","path":"db/migrate/20150303212157_add_unique_constraint_to_memberships.rb","position":null,"original_position":7,"commit_id":"71fc67de4e3355bd36dd3ceebc9025c3bc8dee24","original_commit_id":"eb1bc80ddf027801b0592d44d967ef3559fd172d","user":{"login":"srt32","id":2181356,"avatar_url":"https://avatars.githubusercontent.com/u/2181356?v=3","gravatar_id":"","url":"https://api.github.com/users/srt32","html_url":"https://github.com/srt32","followers_url":"https://api.github.com/users/srt32/followers","following_url":"https://api.github.com/users/srt32/following{/other_user}","gists_url":"https://api.github.com/users/srt32/gists{/gist_id}","starred_url":"https://api.github.com/users/srt32/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srt32/subscriptions","organizations_url":"https://api.github.com/users/srt32/orgs","repos_url":"https://api.github.com/users/srt32/repos","events_url":"https://api.github.com/users/srt32/events{/privacy}","received_events_url":"https://api.github.com/users/srt32/received_events","type":"User","site_admin":false},"body":"I am not sure... I wrapped it in a transaction in 71fc67d","created_at":"2015-03-04T00:52:35Z","updated_at":"2015-03-04T00:52:35Z","html_url":"https://github.com/thoughtbot/hound/pull/703#discussion_r25743628","pull_request_url":"https://api.github.com/repos/thoughtbot/hound/pulls/703","_links":{"self":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/comments/25743628"},"html":{"href":"https://github.com/thoughtbot/hound/pull/703#discussion_r25743628"},"pull_request":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/703"}}},"pull_request":{"url":"https://api.github.com/repos/thoughtbot/hound/pulls/703","id":30421047,"html_url":"https://github.com/thoughtbot/hound/pull/703","diff_url":"https://github.com/thoughtbot/hound/pull/703.diff","patch_url":"https://github.com/thoughtbot/hound/pull/703.patch","issue_url":"https://api.github.com/repos/thoughtbot/hound/issues/703","number":703,"state":"open","locked":false,"title":"Adds unique constraint to memberships","user":{"login":"srt32","id":2181356,"avatar_url":"https://avatars.githubusercontent.com/u/2181356?v=3","gravatar_id":"","url":"https://api.github.com/users/srt32","html_url":"https://github.com/srt32","followers_url":"https://api.github.com/users/srt32/followers","following_url":"https://api.github.com/users/srt32/following{/other_user}","gists_url":"https://api.github.com/users/srt32/gists{/gist_id}","starred_url":"https://api.github.com/users/srt32/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srt32/subscriptions","organizations_url":"https://api.github.com/users/srt32/orgs","repos_url":"https://api.github.com/users/srt32/repos","events_url":"https://api.github.com/users/srt32/events{/privacy}","received_events_url":"https://api.github.com/users/srt32/received_events","type":"User","site_admin":false},"body":"There are duplicate `membership` records in the database:\r\n\r\n```\r\nSELECT distinct(user_id)\r\nFROM memberships\r\nGROUP BY user_id, repo_id\r\nHAVING count(*) > 1;\r\n```\r\n\r\nRemoving these records and then applying the unique key should prevent these\r\nduplicates from happening in the future. If in routine usage, this unique\r\nconstraint is broken, we will now get exceptions (that we'll need to fix)\r\ninstead of bad data.\r\n\r\nThis PR removes the `membership` rake tasks because given the new DB constraints\r\nit should not be possible to have bad data (that the tasks used to clean up).\r\n\r\nhttps://trello.com/c/rVCmKMc1/533-there-are-duplicate-memberships","created_at":"2015-03-03T22:48:23Z","updated_at":"2015-03-04T00:52:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"61748d599a4bddea2773e563343544a8ca98a21e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/thoughtbot/hound/pulls/703/commits","review_comments_url":"https://api.github.com/repos/thoughtbot/hound/pulls/703/comments","review_comment_url":"https://api.github.com/repos/thoughtbot/hound/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thoughtbot/hound/issues/703/comments","statuses_url":"https://api.github.com/repos/thoughtbot/hound/statuses/71fc67de4e3355bd36dd3ceebc9025c3bc8dee24","head":{"label":"thoughtbot:st-dup-memberships","ref":"st-dup-memberships","sha":"71fc67de4e3355bd36dd3ceebc9025c3bc8dee24","user":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"repo":{"id":7411076,"name":"hound","full_name":"thoughtbot/hound","owner":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thoughtbot/hound","description":"Review your Ruby, JavaScript, CoffeeScript, and SCSS code for style guide violations with a trusty hound.","fork":false,"url":"https://api.github.com/repos/thoughtbot/hound","forks_url":"https://api.github.com/repos/thoughtbot/hound/forks","keys_url":"https://api.github.com/repos/thoughtbot/hound/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thoughtbot/hound/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thoughtbot/hound/teams","hooks_url":"https://api.github.com/repos/thoughtbot/hound/hooks","issue_events_url":"https://api.github.com/repos/thoughtbot/hound/issues/events{/number}","events_url":"https://api.github.com/repos/thoughtbot/hound/events","assignees_url":"https://api.github.com/repos/thoughtbot/hound/assignees{/user}","branches_url":"https://api.github.com/repos/thoughtbot/hound/branches{/branch}","tags_url":"https://api.github.com/repos/thoughtbot/hound/tags","blobs_url":"https://api.github.com/repos/thoughtbot/hound/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thoughtbot/hound/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thoughtbot/hound/git/refs{/sha}","trees_url":"https://api.github.com/repos/thoughtbot/hound/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thoughtbot/hound/statuses/{sha}","languages_url":"https://api.github.com/repos/thoughtbot/hound/languages","stargazers_url":"https://api.github.com/repos/thoughtbot/hound/stargazers","contributors_url":"https://api.github.com/repos/thoughtbot/hound/contributors","subscribers_url":"https://api.github.com/repos/thoughtbot/hound/subscribers","subscription_url":"https://api.github.com/repos/thoughtbot/hound/subscription","commits_url":"https://api.github.com/repos/thoughtbot/hound/commits{/sha}","git_commits_url":"https://api.github.com/repos/thoughtbot/hound/git/commits{/sha}","comments_url":"https://api.github.com/repos/thoughtbot/hound/comments{/number}","issue_comment_url":"https://api.github.com/repos/thoughtbot/hound/issues/comments{/number}","contents_url":"https://api.github.com/repos/thoughtbot/hound/contents/{+path}","compare_url":"https://api.github.com/repos/thoughtbot/hound/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thoughtbot/hound/merges","archive_url":"https://api.github.com/repos/thoughtbot/hound/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thoughtbot/hound/downloads","issues_url":"https://api.github.com/repos/thoughtbot/hound/issues{/number}","pulls_url":"https://api.github.com/repos/thoughtbot/hound/pulls{/number}","milestones_url":"https://api.github.com/repos/thoughtbot/hound/milestones{/number}","notifications_url":"https://api.github.com/repos/thoughtbot/hound/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thoughtbot/hound/labels{/name}","releases_url":"https://api.github.com/repos/thoughtbot/hound/releases{/id}","created_at":"2013-01-02T18:12:40Z","updated_at":"2015-03-03T19:32:35Z","pushed_at":"2015-03-04T00:52:19Z","git_url":"git://github.com/thoughtbot/hound.git","ssh_url":"git@github.com:thoughtbot/hound.git","clone_url":"https://github.com/thoughtbot/hound.git","svn_url":"https://github.com/thoughtbot/hound","homepage":"https://houndci.com","size":15688,"stargazers_count":801,"watchers_count":801,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":152,"mirror_url":null,"open_issues_count":25,"forks":152,"open_issues":25,"watchers":801,"default_branch":"master"}},"base":{"label":"thoughtbot:master","ref":"master","sha":"7094945d9e58885c64d856212ea462306eb54800","user":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"repo":{"id":7411076,"name":"hound","full_name":"thoughtbot/hound","owner":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thoughtbot/hound","description":"Review your Ruby, JavaScript, CoffeeScript, and SCSS code for style guide violations with a trusty hound.","fork":false,"url":"https://api.github.com/repos/thoughtbot/hound","forks_url":"https://api.github.com/repos/thoughtbot/hound/forks","keys_url":"https://api.github.com/repos/thoughtbot/hound/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thoughtbot/hound/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thoughtbot/hound/teams","hooks_url":"https://api.github.com/repos/thoughtbot/hound/hooks","issue_events_url":"https://api.github.com/repos/thoughtbot/hound/issues/events{/number}","events_url":"https://api.github.com/repos/thoughtbot/hound/events","assignees_url":"https://api.github.com/repos/thoughtbot/hound/assignees{/user}","branches_url":"https://api.github.com/repos/thoughtbot/hound/branches{/branch}","tags_url":"https://api.github.com/repos/thoughtbot/hound/tags","blobs_url":"https://api.github.com/repos/thoughtbot/hound/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thoughtbot/hound/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thoughtbot/hound/git/refs{/sha}","trees_url":"https://api.github.com/repos/thoughtbot/hound/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thoughtbot/hound/statuses/{sha}","languages_url":"https://api.github.com/repos/thoughtbot/hound/languages","stargazers_url":"https://api.github.com/repos/thoughtbot/hound/stargazers","contributors_url":"https://api.github.com/repos/thoughtbot/hound/contributors","subscribers_url":"https://api.github.com/repos/thoughtbot/hound/subscribers","subscription_url":"https://api.github.com/repos/thoughtbot/hound/subscription","commits_url":"https://api.github.com/repos/thoughtbot/hound/commits{/sha}","git_commits_url":"https://api.github.com/repos/thoughtbot/hound/git/commits{/sha}","comments_url":"https://api.github.com/repos/thoughtbot/hound/comments{/number}","issue_comment_url":"https://api.github.com/repos/thoughtbot/hound/issues/comments{/number}","contents_url":"https://api.github.com/repos/thoughtbot/hound/contents/{+path}","compare_url":"https://api.github.com/repos/thoughtbot/hound/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thoughtbot/hound/merges","archive_url":"https://api.github.com/repos/thoughtbot/hound/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thoughtbot/hound/downloads","issues_url":"https://api.github.com/repos/thoughtbot/hound/issues{/number}","pulls_url":"https://api.github.com/repos/thoughtbot/hound/pulls{/number}","milestones_url":"https://api.github.com/repos/thoughtbot/hound/milestones{/number}","notifications_url":"https://api.github.com/repos/thoughtbot/hound/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thoughtbot/hound/labels{/name}","releases_url":"https://api.github.com/repos/thoughtbot/hound/releases{/id}","created_at":"2013-01-02T18:12:40Z","updated_at":"2015-03-03T19:32:35Z","pushed_at":"2015-03-04T00:52:19Z","git_url":"git://github.com/thoughtbot/hound.git","ssh_url":"git@github.com:thoughtbot/hound.git","clone_url":"https://github.com/thoughtbot/hound.git","svn_url":"https://github.com/thoughtbot/hound","homepage":"https://houndci.com","size":15688,"stargazers_count":801,"watchers_count":801,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":152,"mirror_url":null,"open_issues_count":25,"forks":152,"open_issues":25,"watchers":801,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/703"},"html":{"href":"https://github.com/thoughtbot/hound/pull/703"},"issue":{"href":"https://api.github.com/repos/thoughtbot/hound/issues/703"},"comments":{"href":"https://api.github.com/repos/thoughtbot/hound/issues/703/comments"},"review_comments":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/703/comments"},"review_comment":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/703/commits"},"statuses":{"href":"https://api.github.com/repos/thoughtbot/hound/statuses/71fc67de4e3355bd36dd3ceebc9025c3bc8dee24"}}}}