lib/deprec/recipes/mysql.rb in isaac-deprec-1.99.30 vs lib/deprec/recipes/mysql.rb in isaac-deprec-1.99.32
- old
+ new
@@ -1,21 +1,25 @@
# Copyright 2006-2008 by Mike Bailey. All rights reserved.
Capistrano::Configuration.instance(:must_exist).load do
namespace :deprec do
namespace :mysql do
+ set :mysql_admin_user, 'root'
+ set(:mysql_admin_pass) { Capistrano::CLI.password_prompt "Enter database password for '#{mysql_admin_user}':"}
+
# Installation
desc "Install mysql"
task :install, :roles => :db do
install_deps
+ start
# symlink_mysql_sockfile # XXX still needed?
end
# Install dependencies for Mysql
task :install_deps, :roles => :db do
- apt.install( {:base => %w(mysql-server mysql-client)}, :stable )
+ apt.install( {:base => %w(mysql-server mysql-client libmysqlclient15-dev)}, :stable )
end
# task :symlink_mysql_sockfile, :roles => :db do
# # rails puts "socket: /tmp/mysql.sock" into config/database.yml
# # this is not the location for our ubuntu's mysql socket file
@@ -78,9 +82,34 @@
task :backup, :roles => :db do
end
task :restore, :roles => :db do
+ end
+
+ desc "Create a mysql user"
+ task :create_user, :roles => :db do
+ # TBA
+ end
+
+ desc "Create a database"
+ task :create_database, :roles => :db do
+ cmd = "CREATE DATABASE IF NOT EXISTS #{db_name}"
+ run "mysql -u #{mysql_admin_user} -p -e '#{cmd}'" do |channel, stream, data|
+ if data =~ /^Enter password:/
+ channel.send_data "#{mysql_admin_pass}\n"
+ end
+ end
+ end
+
+ desc "Grant user access to database"
+ task :grant_user_access_to_database, :roles => :db do
+ cmd = "GRANT ALL PRIVILEGES ON #{db_name}.* TO '#{db_user}'@localhost IDENTIFIED BY '#{db_password}';"
+ run "mysql -u #{mysql_admin_user} -p #{db_name} -e \"#{cmd}\"" do |channel, stream, data|
+ if data =~ /^Enter password:/
+ channel.send_data "#{mysql_admin_pass}\n"
+ end
+ end
end
end
end
end