Sha256: 6331702b5788d8511a22f92f207e8f2cbea01780c886e4df639df8866581daa8
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require 'yaml' Capistrano::Configuration.instance.load do namespace :deploy do namespace :prepare do task :database do set_unless :db_admin_user, 'root' set_unless :db_admin_password, Capistrano::CLI.password_prompt("Type your mysql password for user #{db_admin_user}: ") set_unless :db_name, application.to_s + '_' + rails_env.to_s set_unless :db_password, database_config['password'] unless database_exits? create_database end setup_database_permissions end end end def database_exits? exists = false run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"show databases;\"" do |channel, stream, data| exists = exists || data.include?(db_name) end exists end def create_database create_sql = <<-SQL CREATE DATABASE #{db_name}; SQL run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"#{create_sql}\"" end def setup_database_permissions grant_sql = <<-SQL GRANT ALL PRIVILEGES ON #{db_name}.* TO #{application}@localhost IDENTIFIED BY '#{db_password}'; SQL run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"#{grant_sql}\"" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ms_deploy-0.0.1 | lib/ms_deploy/recipes/mysql.rb |