Sha256: cae4c796b315abca34bf503441613ec819a872b9e7a49be38a14ab6b14e35acc

Contents?: true

Size: 902 Bytes

Versions: 9

Compression:

Stored size: 902 Bytes

Contents

# coding: UTF-8

require 'rake'

namespace :dad do
  namespace :db do
    task :create do
      config = YAML.load_file("#{Rails.root}/config/database.yml")
      
      system("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")
      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

9 entries across 9 versions & 1 rubygems

Version Path
daddy-0.0.12 lib/tasks/db_create.rake
daddy-0.0.11 lib/tasks/db_create.rake
daddy-0.0.10 lib/tasks/db_create.rake
daddy-0.0.9 lib/tasks/db_create.rake
daddy-0.0.8 lib/tasks/db_create.rake
daddy-0.0.7 lib/tasks/db_create.rake
daddy-0.0.6 lib/tasks/db_create.rake
daddy-0.0.5 lib/tasks/db_create.rake
daddy-0.0.4 lib/tasks/db_create.rake