提交 8e3e117d 编写于 作者: K Kevin Skoglund 提交者: Michael Koziarski

rake db:migrate:status displays status of migrations [#4947 state:resolved]

Signed-off-by: NMichael Koziarski <michael@koziarski.com>
上级 fb7715b2
......@@ -171,6 +171,31 @@ namespace :db do
ActiveRecord::Migrator.run(:down, "db/migrate/", version)
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end
desc "Display status of migrations"
task :status => :environment do
config = ActiveRecord::Base.configurations[Rails.env || 'development']
db_list = ActiveRecord::Base.connection.select_values("SELECT version FROM schema_migrations")
file_list = []
Dir.foreach(File.join(Rails.root, 'db', 'migrate')) do |file|
# only files matching "20091231235959_some_name.rb" pattern
if match_data = /(\d{14})_(.+)\.rb/.match(file)
status = db_list.delete(match_data[1]) ? 'up' : 'down'
file_list << [status, match_data[1], match_data[2]]
end
end
# output
puts "\ndatabase: #{config['database']}\n\n"
puts "#{"Status".center(8)} #{"Migration ID".ljust(14)} Migration Name"
puts "-" * 50
file_list.each do |file|
puts "#{file[0].center(8)} #{file[1].ljust(14)} #{file[2].humanize}"
end
db_list.each do |version|
puts "#{'up'.center(8)} #{version.ljust(14)} *** NO FILE ***"
end
puts
end
end
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册