Sha256: e2d95222cae95b138e38909d42682db5b2b6119c5edce599f8f3e2e134885112
Contents?: true
Size: 1.38 KB
Versions: 13
Compression:
Stored size: 1.38 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 >> tmp/create_databases.sql") puts puts File.read('tmp/create_databases.sql') if ENV['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
13 entries across 13 versions & 1 rubygems