You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101_populate_changesets_user_id.rb 634B

123456789101112131415161718
  1. class PopulateChangesetsUserId < ActiveRecord::Migration[4.2]
  2. def self.up
  3. committers = Changeset.connection.select_values("SELECT DISTINCT committer FROM #{Changeset.table_name}")
  4. committers.each do |committer|
  5. next if committer.blank?
  6. if committer.strip =~ /^([^<]+)(<(.*)>)?$/
  7. username, email = $1.strip, $3
  8. u = User.find_by_login(username)
  9. u ||= User.find_by_mail(email) unless email.blank?
  10. Changeset.where(["committer = ?", committer]).update_all("user_id = #{u.id}") unless u.nil?
  11. end
  12. end
  13. end
  14. def self.down
  15. Changeset.update_all('user_id = NULL')
  16. end
  17. end