Created
February 22, 2010 23:49
-
-
Save duncanbeevers/311675 to your computer and use it in GitHub Desktop.
Check whether migrations need to be run without requiring the whole app
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
namespace :db do | |
task :uptodate do | |
if pending_migrations.blank? | |
puts "Migrations are up-to-date" | |
else | |
puts "The following migrations are pending:" | |
puts pending_migrations.map { |mp| "%s\t\t%s" % [ mp.version, mp.name ] }.join("\n") | |
end | |
end | |
# Only run this from a single host | |
task :migrate_unless_uptodate do | |
Rake::Task['db:migrate'].invoke unless pending_migrations.blank? | |
end | |
def pending_migrations | |
return @pending_migrations if @pending_migrations | |
require 'active_record' | |
ActiveRecord::Base.configurations = YAML.load_file('config/database.yml') | |
ActiveRecord::Base.establish_connection | |
@pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment