Roll back the most recent migration:
rake db:rollback
Roll back the n
most recent migrations:
rake db:rollback STEP=n
You can find full instructions on the use of Rails migration tasks for rake on the Rails Guide for running migrations.
Here's some more:
rake db:migrate
- Run all migrations that haven't been run already
rake db:migrate VERSION=20080906120000
- Run all necessary migrations (up or down) to get to the given version
rake db:migrate RAILS_ENV=test
- Run migrations in the given environment
rake db:migrate:redo
- Roll back one migration and run it again
rake db:migrate:redo STEP=n
- Roll back the last n
migrations and run them again
rake db:migrate:up VERSION=20080906120000
- Run the up
method for the given migration
rake db:migrate:down VERSION=20080906120000
- Run the down
method for the given migration
And to answer your question about where you get a migration's version number from:
The version is the numerical prefix on the migration's filename. For
example, to migrate to version 20080906120000 run
$ rake db:migrate VERSION=20080906120000
(From Running Migrations in the Rails Guides)