To rest my brain I wrote two rake tasks to show the installed and pending migrations. Feel free to use it for your own - just copy it to a .rake file in your
namespace :db do
namespace :migrate do
desc 'Shows installed migrations'
task :installed => :environment do
mt = ActiveRecord::Migrator.new(:up, "db/migrate/")
list = mt.migrations.select{ |mi| mt.migrated.include?(mi.version.to_i) }
print_migration_list(list)
end
desc 'Shows pending migrations'
task :pending => :environment do
mt = ActiveRecord::Migrator.new(:up, "db/migrate/")
print_migration_list(mt.pending_migrations)
end
end
end
def print_migration_list(migrations)
return if migrations.empty?
max_length = migrations.inject(0) {|max, m| [max, m.name.length].max }
puts "Version Name"
puts "---------------" + "-" * max_length
migrations.each do |m|
puts "#{m.version} #{m.name}"
end
end
See also pastie.org
There is rake db:migrate:status nowadays.
AntwortenLöschen