mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #45377 from gmcgibbon/update_migration_docs
Add more detailed description to migration generator
This commit is contained in:
commit
c47e663750
1 changed files with 21 additions and 11 deletions
|
@ -5,31 +5,41 @@ Description:
|
||||||
A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
|
A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
|
||||||
|
|
||||||
You can name your migration in either of these formats to generate add/remove
|
You can name your migration in either of these formats to generate add/remove
|
||||||
column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
|
column lines from supplied attributes: add_{columns}_to_{table} or remove_{columns}_from_{table}.
|
||||||
|
|
||||||
Example:
|
A migration name containing JoinTable will generate join tables for use with
|
||||||
`bin/rails generate migration AddSslFlag`
|
has_and_belongs_to_many associations.
|
||||||
|
|
||||||
|
You can also name your migration create_{table} along with any attributes to generate a regular table.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
`bin/rails generate migration add_ssl_flag`
|
||||||
|
|
||||||
If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
|
If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
|
||||||
db/migrate/20080514090912_add_ssl_flag.rb
|
db/migrate/20080514090912_add_ssl_flag.rb
|
||||||
|
|
||||||
`bin/rails generate migration AddTitleBodyToPost title:string body:text published:boolean`
|
`bin/rails generate migration add_title_body_published_to_post title:string body:text published:boolean`
|
||||||
|
|
||||||
This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Change migration:
|
This will create db/migrate/20080514090912_add_title_body_published_to_post.rb with this in the migration:
|
||||||
|
|
||||||
add_column :posts, :title, :string
|
add_column :posts, :title, :string
|
||||||
add_column :posts, :body, :text
|
add_column :posts, :body, :text
|
||||||
add_column :posts, :published, :boolean
|
add_column :posts, :published, :boolean
|
||||||
|
|
||||||
Migration names containing JoinTable will generate join tables for use with
|
`bin/rails generate migration create_media_join_table artists musics:uniq`
|
||||||
has_and_belongs_to_many associations.
|
|
||||||
|
|
||||||
Example:
|
This will create a join table migration:
|
||||||
`bin/rails g migration CreateMediaJoinTable artists musics:uniq`
|
|
||||||
|
|
||||||
will create the migration
|
|
||||||
|
|
||||||
create_join_table :artists, :musics do |t|
|
create_join_table :artists, :musics do |t|
|
||||||
# t.index [:artist_id, :music_id]
|
# t.index [:artist_id, :music_id]
|
||||||
t.index [:music_id, :artist_id], unique: true
|
t.index [:music_id, :artist_id], unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
`bin/rails generate migration create_users email:string`
|
||||||
|
|
||||||
|
This will create the migration:
|
||||||
|
|
||||||
|
create_table :users do |t|
|
||||||
|
t.string :email
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue