Created
February 29, 2012 11:50
-
-
Save duncanbeevers/1940309 to your computer and use it in GitHub Desktop.
A set of rake tasks to determine whether migrations need to be run without loading the full app environment
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 | |
task :migrate_unless_uptodate do | |
Rake::Task['db:migrate'].invoke unless pending_migrations.blank? | |
end | |
namespace :schema do | |
task :purge_cached_tables => :environment do | |
ActiveRecord::Base.connection.purge_cached_tables | |
end | |
task :dump => :purge_cached_tables | |
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