Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
09/09/07 05:40:34 (1 year ago)
Author:
nzkoz
Message:

Use attribute pairs instead of the migration name to create add and remove column migrations. Closes #9166 [lifofifo]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/railties/lib/rails_generator/generators/components/migration/USAGE

    r7216 r7422  
    11Description: 
    22    Stubs out a new database migration. Pass the migration name, either 
    3     CamelCased or under_scored, as an argument. A migration class is generated 
    4     in db/migrate prefixed by the latest migration number. 
     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. 
    56 
    67    You can name your migration in either of these formats to generate add/remove 
    7     column lines: AddColumnToTable or RemoveColumnFromTable 
     8    column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable 
    89 
    910Example: 
     
    1314    db/migrate/005_add_ssl_flag.rb 
    1415 
    15     `./script/generate migration AddSslFlagToAccount
     16    `./script/generate migration AddTitleBodyToPost title:string body:text published:boolean
    1617     
    17     This will create the AddSslFlagToAccount in db/migrate/005_add_ssl_flag_to_account.rb with 
     18    This will create the AddTitleBodyToPost in db/migrate/005_add_title_body_to_post.rb with 
    1819    this in the Up migration: 
    1920 
    20       add_column :accounts, :ssl_flag, :type, :null => :no?, :default => :maybe? 
     21      add_column :posts, :title, :string   
     22      add_column :posts, :body, :text   
     23      add_column :posts, :published, :boolean 
    2124 
    2225    And this in the Down migration: 
    2326     
    24       remove_column :accounts, :ssl_flag 
     27      remove_column :posts, :published   
     28      remove_column :posts, :body   
     29      remove_column :posts, :title