Sha256: 36969efabf94242d037b2844f5bf3575fdefb37dc683f3aac5fb8b6af86a39b0

Contents?: true

Size: 968 Bytes

Versions: 2

Compression:

Stored size: 968 Bytes

Contents

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'].gsub(/_/, '-')}-*.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'].include? 'mysql'
    raise RuntimeError, "Cannot find mysql." if mysql.blank?

    sh "#{mysql} #{options} '#{config["database"]}' < db/data.sql"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bard-rake-0.2.0 lib/bard/rake/db.rb
bard-rake-0.1.8 lib/bard/rake/db.rb