Created
August 2, 2012 08:06
-
-
Save flori/3235105 to your computer and use it in GitHub Desktop.
List migrations in a rails project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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