Active Record Migrations Flashcards
Whats the easiest way to add a migration for a new model?
rails g model Name name:string description:text
How do you create a standalone migration?
rails g migration AddPartNumberToProduct part_number:string
This will create a migration file with the following line:
add_column :products, :part_number, :string
How do you create a migration to add a part number t o a product, with an index?
rails g migration AddPartNumberToProduct part_number:string:index
How do you generate a migration to remove a column from a database table?
rails g migration RemovePartNumberFromProducts part_number:string
How can you add multiple columns to a database table?
rails g migration AddDetailsToProduct description:text price:decimal
How can you generate a migration file for a new table?
rails g migration CreateProducts name:string price:decimal
How do you add a user reference column to a database website table?
rails g migration AddUserRefToWebsite user:references
How do you generate a migration to create a join table for two models?
rails g migrations CreateJoinTableUserWebsite user website