Sha256: 015b1a9ab70b9e95709777be169039bf28800143731171c1d22c55d4a6c649e0

Contents?: true

Size: 962 Bytes

Versions: 8

Compression:

Stored size: 962 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'] == 'mysql'
    raise RuntimeError, "Cannot find mysql." if mysql.blank?

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bard-rake-0.1.7 lib/bard/rake/db.rb
bard-rake-0.1.6 lib/bard/rake/db.rb
bard-rake-0.1.5 lib/bard/rake/db.rb
bard-rake-0.1.4 lib/bard/rake/db.rb
bard-rake-0.1.3 lib/bard/rake/db.rb
bard-rake-0.1.2 lib/bard/rake/db.rb
bard-rake-0.1.1 lib/bard/rake/db.rb
bard-rake-0.1.0 lib/bard/rake/db.rb