Skip to main content

How to get the schema version number out of your Rails migrations

When you want to revert your Rails migration you need the version number so that you can perform the rollback:
rake db:migration VERSION=?
One way is to access the database and take a look in the schema_info table to find the version number.

An easier way is to add an additional task to Rake (found via the Quoted-Printable):
namespace :db do
desc 'Print the current database migration version number'
task :version => :environment do
puts ActiveRecord::Migrator.current_version
end
end
Copy this code into a file called db_version.rake and place it in the lib/tasks directory within your Rails application.

To find out the current version number, simply run:
rake db:version
Technorati Tags: , , , , ,

Comments

Anonymous said…
Thanks, this was just what I was looking for to track down some strange behavior with schema_migrations in Oracle.