Skip to content

Instantly share code, notes, and snippets.

@flori
Created August 2, 2012 08:06
Show Gist options
  • Save flori/3235105 to your computer and use it in GitHub Desktop.
Save flori/3235105 to your computer and use it in GitHub Desktop.
List migrations in a rails project
def list_migrations
Dir['db/migrate/[0-9]*.rb'].sort_by { |f| File.basename(f).to_i }
end
namespace :db do
namespace :migrate do
namespace :list do
desc 'List all paths to migration files starting with the last one'
task :paths do
puts list_migrations
end
desc 'List all versions of migration files starting with the last one'
task :versions do
puts list_migrations.map { |m|
File.basename(m) =~ /(\d+)_?([^.]+)/ and "%u # %s" % $~.captures
}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment