Sha256: 13cdb760f940efa1e48546667ad97af3af85ae3e654c4fac4f5e01b3daab612e

Contents?: true

Size: 1.25 KB

Versions: 15

Compression:

Stored size: 1.25 KB

Contents

# coding: UTF-8

require 'rake'

namespace :dad do
  namespace :db do
    
    desc 'database.yml に従ってDBを作成します。'
    task :create do
      config = YAML.load_file("#{Rails.root}/config/database.yml")
      
      FileUtils.mkdir_p("tmp")
      system("echo '# mysql ddl' > tmp/create_databases.sql")
  
      config.each do |env, props|
        puts "database for environment #{env}"
        system("echo 'drop database if exists #{props['database']};' >> tmp/create_databases.sql")
        system("echo 'create database #{props['database']};' >> tmp/create_databases.sql")
        system("echo 'grant all on #{props['database']}.* to #{props['username']} identified by \"#{props['password']}\";' >> tmp/create_databases.sql")

        if ENV['FILE']
          system("echo 'grant all on #{props['database']}.* to #{props['username']}@localhost identified by \"#{props['password']}\";' >> tmp/create_databases.sql")
          system("echo 'grant file on *.* to #{props['username']}@localhost;' >> tmp/create_databases.sql")
        end
      end
      
      system("echo >> tmp/create_databases.sql")
  
      system("cat tmp/create_databases.sql")
      ret = system("mysql -u root -p < tmp/create_databases.sql")
      fail unless ret
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
daddy-0.2.3 lib/tasks/db_create.rake
daddy-0.2.1 lib/tasks/db_create.rake
daddy-0.1.26 lib/tasks/db_create.rake
daddy-0.1.25 lib/tasks/db_create.rake
daddy-0.1.24 lib/tasks/db_create.rake
daddy-0.1.23 lib/tasks/db_create.rake
daddy-0.1.22 lib/tasks/db_create.rake
daddy-0.1.20 lib/tasks/db_create.rake
daddy-0.1.18 lib/tasks/db_create.rake
daddy-0.1.17 lib/tasks/db_create.rake
daddy-0.1.15 lib/tasks/db_create.rake
daddy-0.1.14 lib/tasks/db_create.rake
daddy-0.1.13 lib/tasks/db_create.rake
daddy-0.1.12 lib/tasks/db_create.rake
daddy-0.1.11 lib/tasks/db_create.rake