/ Published in: Rails
These methods are used for the easy creation and maintenance of database tables. Here\'s a good cheat sheet. http://dizzy.co.uk/rubyonrails/cheatsheets/rails-migrations
Expand |
Embed | Plain Text
############################### #Common Migration Tasks ############################### #Generate a new migration template ruby script/generate migration AddNewColumnNameToModel column_name:[integer, string, boolean, text] #Create a new migration for adding the "sessions" table 1. rake db:session:create 2. Uncomment #ActionController::Base.session_store = :active_record_store form /my_rails_app/config/initializers/session_store.rb #Migrate to Version 0 rake db:migrate VERSION=0 #Applies any pending migrations to the database db:migrate #Rolls back one database migration and then reapplies it db:migrate:redo #Drops the database and reapplies all migrations db:migrate:reset #Applies the next pending migration db:up #Rolls back the last applied migration db:down #Creates the database from the environment specified db:create:all db:create #Removes the database from the environment specified db:drop:all (Rails +2.0) db:drop #Drops and re-creates the database db:reset ############################### #Table modification methods ############################### #Create a new table. create_table(name, options) #Drop the specified table. drop_table(name) #Rename the table from old_name to new_name. rename_table(old_name, new_name) ############################### #Column modification methods ############################### #Add a new column to table. add_column(table, column, type, options) #Rename the specified column from old_column_name to new_column_name. rename_column(table, old_column_name, new_column_name) #Modify a column by changing it to a different type. change_column(table, column, type, options) #Remove the column from the specified table. Index modification methods remove_column(table, column) #Add a new index on the specified columns. add_index(table, columns, options) #Drop the specified index. remove_index(table, index)
You need to login to post a comment.
