|
Revision 7422, 1.1 kB
(checked in by nzkoz, 10 months ago)
|
Use attribute pairs instead of the migration name to create add and remove column migrations. Closes #9166 [lifofifo]
|
| Line | |
|---|
| 1 |
Description: |
|---|
| 2 |
Stubs out a new database migration. Pass the migration name, either |
|---|
| 3 |
CamelCased or under_scored, and an optional list of attribute pairs as arguments. |
|---|
| 4 |
|
|---|
| 5 |
A migration class is generated in db/migrate prefixed by the latest migration number. |
|---|
| 6 |
|
|---|
| 7 |
You can name your migration in either of these formats to generate add/remove |
|---|
| 8 |
column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable |
|---|
| 9 |
|
|---|
| 10 |
Example: |
|---|
| 11 |
`./script/generate migration AddSslFlag` |
|---|
| 12 |
|
|---|
| 13 |
With 4 existing migrations, this creates the AddSslFlag migration in |
|---|
| 14 |
db/migrate/005_add_ssl_flag.rb |
|---|
| 15 |
|
|---|
| 16 |
`./script/generate migration AddTitleBodyToPost title:string body:text published:boolean` |
|---|
| 17 |
|
|---|
| 18 |
This will create the AddTitleBodyToPost in db/migrate/005_add_title_body_to_post.rb with |
|---|
| 19 |
this in the Up migration: |
|---|
| 20 |
|
|---|
| 21 |
add_column :posts, :title, :string |
|---|
| 22 |
add_column :posts, :body, :text |
|---|
| 23 |
add_column :posts, :published, :boolean |
|---|
| 24 |
|
|---|
| 25 |
And this in the Down migration: |
|---|
| 26 |
|
|---|
| 27 |
remove_column :posts, :published |
|---|
| 28 |
remove_column :posts, :body |
|---|
| 29 |
remove_column :posts, :title |
|---|