rake db:version

Tuesday, September 26

I often find myself needing to know what migration version my database is at. There is the ./script/about script, which tells me the version number (and a host of other things), but I don’t want to have to look through all that. All I want is the migration number I’m currently at.

Here is a simple rake task you can plop in your lib/tasks directory that will print the current version.


# lib/tasks/db_migration_version.rake
namespace :db do
  desc 'Print the current database migration version number'
  task :version => :environment do
    puts ActiveRecord::Migrator.current_version
  end
end

Example usage:

$ rake db:version
29

Fun!

Comments

Leave a response

  1. TiffaniSeptember 26, 2006 @ 04:07 PM

    Niiiiice…I’ve wanted this for a while now! Thanks!