Created
August 16, 2010 15:22
-
-
Save anonymous/527117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "creates database & database user" | |
task :create_database do | |
set :root_password, Capistrano::CLI.password_prompt("MySQL root password: ") | |
set :db_user, Capistrano::CLI.ui.ask("Application database user: ") | |
set :db_pass, Capistrano::CLI.password_prompt("Password: ") | |
set :db_name, Capistrano::CLI.ui.ask("Database name: ") | |
run "mysql --user=root --password=#{root_password} -e \"CREATE DATABASE IF NOT EXISTS #{db_name}\"" | |
run "mysql --user=root --password=#{root_password} -e \"GRANT ALL PRIVILEGES ON #{db_name}.* TO '#{db_user}'@'localhost' IDENTIFIED BY '#{db_pass}' WITH GRANT OPTION\"" | |
end |
You can't run db:create:all if the code isn't already deployed. The problem I'm running into is I'm deploying to a fresh Vagrant box but it's dying because the DB isn't already created. However when the deploy fails the code is rolled back so there's no way for me to manually do "rake db:create:all".
Capistrano 3 version:
namespace :deploy do
desc "Create database and database user"
task :create_mysql_database do
ask :db_root_password, ''
ask :db_name, fetch(:application)
ask :db_user, 'deploy'
ask :db_pass, ''
on primary fetch(:migration_role) do
execute "mysql --user=root --password=#{fetch(:db_root_password)} -e \"CREATE DATABASE IF NOT EXISTS #{fetch(:db_name)}\""
execute "mysql --user=root --password=#{fetch(:db_root_password)} -e \"GRANT ALL PRIVILEGES ON #{fetch(:db_name)}.* TO '#{fetch(:db_user)}'@'localhost' IDENTIFIED BY '#{fetch(:db_pass)}' WITH GRANT OPTION\""
end
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what's the problem with running rake db:create:all ?