Sha256: 14f43ba1b073fd41be8754e70e4207cdcb4c5129499fa061b608ffd576550ef0

Contents?: true

Size: 1.11 KB

Versions: 12

Compression:

Stored size: 1.11 KB

Contents

class RefactorPeople < ActiveRecord::Migration
  def self.up
    ActiveRecord::Base.establish_connection :users
    create_table :procon_profiles do |t|
      t.column :person_id, :integer, :null => false
      t.column :nickname, :string
      t.column :phone, :string
      t.column :best_call_time, :string
    end
    Person.find(:all).each do |person|
      prof = ProconProfile.new :person => person
      prof.nickname = person.nickname
      prof.phone = person.phone
      prof.best_call_time = person.best_call_time
      prof.save
    end
    remove_column "people", "nickname"
    remove_column "people", "phone"
    remove_column "people", "best_call_time"
  end

  def self.down
    ActiveRecord::Base.establish_connection :users
    add_column "people", "nickname", :string
    add_column "people", "phone", :string
    add_column "people", "best_call_time", :string
    ProconProfile.find(:all).each do |prof|
      person = prof.person
      person.nickname = prof.nickname
      person.phone = prof.phone
      person.best_call_time = prof.best_call_time
      person.save
    end
    drop_table :procon_profiles
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
ae_users_legacy-0.6.14 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.13 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.12 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.11 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.10 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.9 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.8 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.7 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.6 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.5 db/migrate/016_refactor_people.rb
ae_users_legacy-0.6.3 db/migrate/016_refactor_people.rb
ae_users-0.6.0 db/migrate/016_refactor_people.rb