Advertisement
saasbook

naive_migration.rb

Apr 2nd, 2012
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.34 KB | None | 0 0
  1. class ChangeNameToFirstAndLast < ActiveRecord::Migration
  2.   def up
  3.     add_column 'moviegoers', 'first_name', :string
  4.     add_column 'moviegoers', 'last_name', :string
  5.     Moviegoer.all.each do |m|
  6.       m.update_attributes(:first => $1, :last => $2) if
  7.         m.name =~ /^(.*)\s+(.*)$/
  8.     end
  9.     remove_column 'moviegoers', 'name'
  10.   end
  11. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement