Sha256: f4454b5c94093687f830cea5116e80e489a8ccbdcdf64ea8ed2d1398646dbd3e

Contents?: true

Size: 770 Bytes

Versions: 18

Compression:

Stored size: 770 Bytes

Contents

class AddUserIdToTestRuns < ActiveRecord::Migration
  def up
    add_column :test_runs, :user_id, :integer

    agent_emails = TestRun.reorder(nil).pluck("DISTINCT agent_email")
    user_id_by_agent_email = Hash[agent_emails.map { |agent_email|
      email = Mail::Address.new(agent_email)
      [agent_email, User.with_email_address(email.address).pluck(:id)[0]] }]

    puts "\e[94mAssociating users with test runs...\e[0m"
    pbar = ProgressBar.new("test runs", TestRun.count)
    TestRun.pluck(:agent_email, :id).each do |agent_email, id|
      user_id = user_id_by_agent_email[agent_email]
      TestRun.where(id: id).update_all(user_id: user_id) if user_id
      pbar.inc
    end
    pbar.finish
  end

  def down
    remove_column :test_runs, :user_id
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.7.0 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.7.0.beta4 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.7.0.beta3 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.7.0.beta2 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.7.0.beta db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.6.3 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.6.2 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.6.1 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.6.0 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.5.6 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.5.5 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.5.4 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.5.3 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.5.2 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.5.1 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.5.0 db/migrate/20150805233946_add_user_id_to_test_runs.rb
houston-core-0.5.0.beta1 db/migrate/20150805233946_add_user_id_to_test_runs.rb