annotate db/migrate/101_populate_changesets_user_id.rb @ 1433:cfa80f738847 bibliography_testing

Fixed assertion error message.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 08 Oct 2013 17:29:47 +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