Skip to content

Use Say with Time in Migrations

Richard Huang edited this page Oct 10, 2010 · 1 revision

Please go to http://rails-bestpractices.com/posts/46-use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log

Before:


def self.up
  User.find_each do |user|
    user.first_name, user.last_name = user.full_name.split(' ')
    user.save
  end
end

After:


def self.up
  say_with_time("Initialize first_name and last_name for users") do
    User.find_each do |user|
      user.first_name, user.last_name = user.full_name.split(' ')
      user.save
      say(user.id + " was updated.")
    end
  end
end