I Google this info about every 48hours, so I figure it’s time I made it closer to my fingertips. This post is not original. I am blatantly coping from here.
In the order I use them:
Basic migration functions
- create_table(name, options)
- drop_table(name)
- rename_table(old_name, new_name)
- add_column(table_name, column_name, type, options)
- rename_column(table_name, column_name, new_column_name)
- change_column(table_name, column_name, type, options)
- remove_column(table_name, column_name)
- add_index(table_name, column_name, index_type)
- remove_index(table_name, column_name)
Commands I commonly use:
- rake migrate RAILS_ENV=”production”: run on production server after deploying project
- rake db_schema_dump: run after you create a model to capture the schema.rb
- rake db_schema_import: import the schema file into the current database (on error, check if your schema.rb has ”:force => true” on the create table statements
- ./script/generate migration MigrationName: generate a new migration with a new ‘highest’ version (run ’./script/generate migration’ for this info at your fingertips)
- rake migrate: migrate your current database to the most recent version
- rake migrate VERSION=5: migrate your current database to a specific version (in this case, version 5)

