Created
February 28, 2009 08:45
-
-
Save mattwynne/71918 to your computer and use it in GitHub Desktop.
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 | |
namespace :features do | |
def checking_for_config | |
if ActiveRecord::Base.configurations["features"] | |
yield | |
else | |
puts "Unable to prepare features database - it's not defined in your configuration. Skipping. Preparing test database instead." | |
Rake::Task['db:test:prepare'].invoke | |
end | |
end | |
desc "Clones the development database into the features environment" | |
task :prepare => [:environment, 'db:abort_if_pending_migrations'] do | |
Rake::Task['db:features:prepare!'].invoke | |
end | |
desc "Clones the development database into the features environment without checking for pending migrations." | |
task :prepare! => [:environment, 'db:structure:dump'] do | |
checking_for_config do | |
ActiveRecord::Base.establish_connection(:features) | |
ActiveRecord::Base.connection.recreate_database(ActiveRecord::Base.configurations["features"]["database"]) | |
ActiveRecord::Base.establish_connection(:features) | |
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') | |
IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| | |
ActiveRecord::Base.connection.execute(table) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment