aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorKevin Skoglund <kevin@novafabrica.com>2010-06-23 12:45:23 -0400
committerMichael Koziarski <michael@koziarski.com>2010-06-28 14:08:40 +1200
commit8e3e117dbe58fd4fedbb78a3d8e398ab0e415634 (patch)
treecb4d373d3c5c29d4995414c8d6cd3715bd35c324 /activerecord
parentfb7715b2491380becbaa111a4c5a211bac662e97 (diff)
downloadrails-8e3e117dbe58fd4fedbb78a3d8e398ab0e415634.tar.gz
rails-8e3e117dbe58fd4fedbb78a3d8e398ab0e415634.tar.bz2
rails-8e3e117dbe58fd4fedbb78a3d8e398ab0e415634.zip
rake db:migrate:status displays status of migrations [#4947 state:resolved]
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/railties/databases.rake25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 006e64b115..80218d6ff9 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -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).'