Sha256: 6bd830a50495103fae84eadece6c8517920231f827965385ddcf3c03466f1230

Contents?: true

Size: 1.46 KB

Versions: 54

Compression:

Stored size: 1.46 KB

Contents

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|
        next if env == 'default'

        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 'flush privileges;' >> tmp/create_databases.sql")
      system("echo >> tmp/create_databases.sql")

      puts
      puts File.read('tmp/create_databases.sql')

      if ENV['DAD_MYSQL_NO_ROOT_PASSWORD']
        fail unless system("mysql -u root < tmp/create_databases.sql")
      else
        fail unless system("mysql -u root -p < tmp/create_databases.sql")
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
daddy-0.5.34 lib/tasks/db_create.rake
daddy-0.5.33 lib/tasks/db_create.rake
daddy-0.5.32 lib/tasks/db_create.rake
daddy-0.5.31 lib/tasks/db_create.rake
daddy-0.5.30 lib/tasks/db_create.rake
daddy-0.5.29 lib/tasks/db_create.rake
daddy-0.5.28 lib/tasks/db_create.rake
daddy-0.5.27 lib/tasks/db_create.rake
daddy-0.5.26 lib/tasks/db_create.rake
daddy-0.5.25 lib/tasks/db_create.rake
daddy-0.5.24 lib/tasks/db_create.rake
daddy-0.5.23 lib/tasks/db_create.rake
daddy-0.5.22 lib/tasks/db_create.rake
daddy-0.5.21 lib/tasks/db_create.rake
daddy-0.5.20 lib/tasks/db_create.rake
daddy-0.5.19 lib/tasks/db_create.rake
daddy-0.5.18 lib/tasks/db_create.rake
daddy-0.5.17 lib/tasks/db_create.rake
daddy-0.5.16 lib/tasks/db_create.rake
daddy-0.5.15 lib/tasks/db_create.rake