Rails Migrations p2
to roll a migration back, you run rake like this:
rake db:migration VERSION=0 (0 tells it to go back to the beginning.)

if you want to target a version, or environment you would do
rake db:migration VERSION=[some version], RAILS_ENV=[some environment]

The version numbers are in the “schema_migrations” table in the db.  They are also the numeric numbers on the migration files themselves.

How it works:
By default, if you have multiple migrations (say 7 versions), and you only want version 5… you would specify the version, it will run a db migration for version 1, then version 2, all the way up to the target version.

You can also do a rake:db:migrate:up and specify the version, this will only run that one migration version.

rake db:migration:redo rolls back to the previous then up to the last one.


No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *