-
-
Save chytreg/87cef9fcf5d3e5e1db5c to your computer and use it in GitHub Desktop.
fix User duplication in ghcr #ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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