Skip to content

Instantly share code, notes, and snippets.

@chytreg
Created January 20, 2014 16:26
Show Gist options
  • Save chytreg/87cef9fcf5d3e5e1db5c to your computer and use it in GitHub Desktop.
Save chytreg/87cef9fcf5d3e5e1db5c to your computer and use it in GitHub Desktop.
fix User duplication in ghcr #ruby
duplicates = User.group(:username).having("count(*) > 1").count
duplicates.each do |username, count|
next if username.blank?
users = User.where(username: username).order("updated_at DESC")
first = users.shift
user_ids = users.map(&:id)
Event.where(reviewer_id: user_ids).update_all(reviewer_id: first.id)
[:author_id, :committer_id, :last_reviewer_id].each do |field|
Commit.where(field => user_ids).update_all(field => first.id)
end
users.map(&:destroy)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment