Sha256: 7ee95e4bf8185153e7527383f44ccf07b12482df05027f7388c02659f92296dd
Contents?: true
Size: 1.5 KB
Versions: 12
Compression:
Stored size: 1.5 KB
Contents
require 'rake' namespace :dad do namespace :db do desc 'database.yml に従ってDBを作成します。' task :create do config = YAML.load(ERB.new(File.read('config/database.yml'), 0, '-').result) 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['MYSQL_NO_ROOT_PASSWORD'] fail unless system("mysql -u root < tmp/create_databases.sql") else fail unless system("mysql -u #{ENV['MYSQL_ROOT'] || 'root'} -p < tmp/create_databases.sql") end end end end
Version data entries
12 entries across 12 versions & 1 rubygems