mirror of https://github.com/rails/rails
rake db:migrate:status displays status of migrations [#4947 state:resolved]
Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
parent
fb7715b249
commit
8e3e117dbe
|
@ -171,6 +171,31 @@ namespace :db do
|
||||||
ActiveRecord::Migrator.run(:down, "db/migrate/", version)
|
ActiveRecord::Migrator.run(:down, "db/migrate/", version)
|
||||||
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
||||||
|
|
Loading…
Reference in New Issue