lib/bard/rake.rb in bard-0.8.26 vs lib/bard/rake.rb in bard-0.8.27

- old
+ new

@@ -1,9 +1,34 @@ task :restart do system "touch tmp/restart.txt" system "touch tmp/debug.txt" if ENV["DEBUG"] == 'true' end +namespace :db do + desc "Dump the current database to db/data.sql" + task :dump => :"backup:db" do + config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] + db_file = Dir.glob("../#{config['database']}-*.sql").first + FileUtils.move db_file, "db/data.sql" + end + + desc "Load the db/data.sql data into the current database." + task :load => :environment do + config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] + Rake::Task["db:drop"].invoke + Rake::Task["db:create"].invoke + mysql = `which mysql`.strip + options = " -u#{config['username']}" + options += " -p#{config['password']}" if config['password'] + options += " -h #{config['host']}" if config['host'] + + raise RuntimeError, "I only work with mysql." unless config['adapter'] == 'mysql' + raise RuntimeError, "Cannot find mysql." if mysql.blank? + + sh "#{mysql} #{options} '#{config["database"]}' < db/data.sql" + end +end + desc "Bootstrap project" task :bootstrap => %w(bootstrap:files gems:install db:create db:migrate restart) namespace :bootstrap do desc "Bootstrap project to run tests"