Sha256: e350d10cb40760b3e00ab6d53582c8286deac1c4b8af60c051624497c39d0d2e

Contents?: true

Size: 619 Bytes

Versions: 27

Compression:

Stored size: 619 Bytes

Contents

class SplitUsersNameIntoFirstAndLast < ActiveRecord::Migration
  def up
    add_column :users, :first_name, :string
    add_column :users, :last_name, :string

    User.reset_column_information
    User.transaction do
      User.all.each do |user|
        names = user.read_attribute(:name).split(" ")
        names = names * 2 if names.length == 1
        user.first_name, user.last_name = *names
        puts "\"#{user.name}\" => \"#{user.first_name}\", \"#{user.last_name}\""
        user.save!
      end
    end
  end

  def down
    remove_column :users, :first_name
    remove_column :users, :last_name
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
houston-core-0.9.2 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.9.1 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.9.0 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.9.0.rc1 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.8.4 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.8.3 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.8.2 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.8.1 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.8.0 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.8.0.pre2 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.8.0.pre db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.7.0 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.7.0.beta4 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.7.0.beta3 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.7.0.beta2 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.7.0.beta db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.6.3 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.6.2 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.6.1 db/migrate/20121026014457_split_users_name_into_first_and_last.rb
houston-core-0.6.0 db/migrate/20121026014457_split_users_name_into_first_and_last.rb