Sha256: ed006e2c7c152e23c79943fccc2ee3bada1eb94a99b87c91873d871624d57c29

Contents?: true

Size: 811 Bytes

Versions: 11

Compression:

Stored size: 811 Bytes

Contents

require_relative 'task_helper'

namespace :dad do
  namespace :db do

    desc "データベースをロードします。"
    task :load do
      dump_file = ENV['DUMP_FILE'] || ask('ダンプファイル', :required => true)

      config = YAML.load(ERB.new(File.read('config/database.yml'), 0, '-').result)[Rails.env]

      host = config['host'] || 'localhost'
      database = config['database']
      user = config['username']
      password = config['password']

      if dump_file.end_with?('.gz')
        run "zcat #{dump_file} | mysql -u #{user} -p#{password} -h #{host} #{database}",
          :mask => [/-p[^ ]+/, '-pFILTERED']
      else
        run "mysql -u #{user} -p#{password} -h #{host} #{database} < #{dump_file}",
          :mask => [/-p[^ ]+/, '-pFILTERED']
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
daddy-0.9.13 lib/tasks/db_load.rake
daddy-0.9.12 lib/tasks/db_load.rake
daddy-0.9.11 lib/tasks/db_load.rake
daddy-0.9.10 lib/tasks/db_load.rake
daddy-0.9.9 lib/tasks/db_load.rake
daddy-0.9.8 lib/tasks/db_load.rake
daddy-0.9.7 lib/tasks/db_load.rake
daddy-0.9.6 lib/tasks/db_load.rake
daddy-0.9.5 lib/tasks/db_load.rake
daddy-0.9.4 lib/tasks/db_load.rake
daddy-0.9.3 lib/tasks/db_load.rake