Migration(rake)

rake command executes migration.

rake db:migrate

This command should be executed application root.
rake:migrate compares schema_migrations table and db/migrate folder,
it can find migration files which are not executed.
We can rollback any steps(status) we can.

rake db commands list

Command Description
db:migrate Migrate to the designated VERSION(if missing VERSION, go latest)
db:rollback Rollback steps you decide
db:migrate:up Execute up method of you decide migration file
db:migrate:down Execute down method of you decide migration file
db:migrate:redo Rollback several steps and redo
db:migrate:reset Delete database and redo
db:drop:all Delete database(only)

Example

rake db:migrate VERSION=20140215175710   # version
rake db:rollback STEP=5                  # 5 steps
rake db:migrate:up VERSION=20140215175710 # execute 20140215175710xxx migration file
rake db:migrate:down VERSION=20140215175710 
rake db:migrate:redo STEP=5              # rollback 5steps and redo
rake db:migrate:reset                    # delete database

RAILS_ENV

Basically, rake commands are applied to default database defined by database.yml
Default is development
If you want to do other database, set others

rake db:migrate RAILS_ENV=test

VERBOSE option

VERBOSE is to display process of migration
You can off this.

rake db:migrate VERBOSE=false

Recreate database using schema file

Rails keeps schema history(different from migration), db/schema.rb.
This is like all-migration files together.

Load schema file

rake db:schema:load

Delete current database and load schema

rake db:reset

Delete database

rake db:drop:all