annotate db/migrate/101_populate_changesets_user_id.rb @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents 513646585e45
children
rev   line source
Chris@0 1 class PopulateChangesetsUserId < ActiveRecord::Migration
Chris@0 2 def self.up
Chris@0 3 committers = Changeset.connection.select_values("SELECT DISTINCT committer FROM #{Changeset.table_name}")
Chris@0 4 committers.each do |committer|
Chris@0 5 next if committer.blank?
Chris@0 6 if committer.strip =~ /^([^<]+)(<(.*)>)?$/
Chris@0 7 username, email = $1.strip, $3
Chris@0 8 u = User.find_by_login(username)
Chris@0 9 u ||= User.find_by_mail(email) unless email.blank?
Chris@0 10 Changeset.update_all("user_id = #{u.id}", ["committer = ?", committer]) unless u.nil?
Chris@0 11 end
Chris@0 12 end
Chris@0 13 end
Chris@0 14
Chris@0 15 def self.down
Chris@0 16 Changeset.update_all('user_id = NULL')
Chris@0 17 end
Chris@0 18 end