× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Introduction to Rails database migrations

Milos Blasko
Aug 12, 2014

Q: What was the request about?
I would like to learn how Rails migrations work.

Q: How did you help with the request?
I explained the fundamentals and went through several examples inside Keeya's own project

Q: Any best practices & key learnings you can share?

If you need to put any ActiveRecord commands inside your migration, for example

add_column :users, :status, :string

User.update_all("status = 'single'")

don't use def change but

def up
 add_column :users, :status, :string

 User.update_all("status = 'single'")
end

def down
 remove_column :users, :status
end

Otherwise your migration would cracsh during rake db:rollback.