Active Record Migrations Flashcards

1
Q

Whats the easiest way to add a migration for a new model?

A

rails g model Name name:string description:text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you create a standalone migration?

A

rails g migration AddPartNumberToProduct part_number:string

This will create a migration file with the following line:

add_column :products, :part_number, :string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a migration to add a part number t o a product, with an index?

A

rails g migration AddPartNumberToProduct part_number:string:index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you generate a migration to remove a column from a database table?

A

rails g migration RemovePartNumberFromProducts part_number:string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you add multiple columns to a database table?

A

rails g migration AddDetailsToProduct description:text price:decimal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you generate a migration file for a new table?

A

rails g migration CreateProducts name:string price:decimal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you add a user reference column to a database website table?

A

rails g migration AddUserRefToWebsite user:references

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you generate a migration to create a join table for two models?

A

rails g migrations CreateJoinTableUserWebsite user website

How well did you know this?
1
Not at all
2
3
4
5
Perfectly