Great new migration feature in Rails 2.1

Have you ever forgot to add the magic timestamp fields created_at or created_on and updated_at or updated_on to all of your tables and at some point wanted to go back and do it?

Well now this task will take much less code. Simply do this to fix your issues:

1
2
3
4
5
6
7
8
9
def self.up
  add_timestamps :users
  add_timestamps :auctions
end

def self.down
  remove_timestamps :users
  remove_timestamps :auctions
end


The parameter passed to the add_Timestamps and remove_timestamps methods is teh table name(s) to add the timestamp fields to.

Leave a Reply