lib/kapify/pg/configuration.rb in kapify-0.1.0 vs lib/kapify/pg/configuration.rb in kapify-0.1.1

- old
+ new

@@ -12,27 +12,29 @@ namespace :kapify do namespace :pg do desc "Create user for application" task :create_user, roles: :pg do - pg_params = "-p #{pg_port}" - check_user = %Q[#{sudo} -u postgres psql #{pg_params} postgres -c "select * from pg_user where usename='#{pg_user}'" | grep -c '#{pg_user}'] - add_user = %Q[#{sudo} -u postgres psql #{pg_params} -c "create user #{pg_user}"] - run "#{check_user} || #{add_user}" - run %Q{#{sudo} -u postgres psql #{pg_params} -c "alter user #{pg_user} with password '#{pg_password}'" } + if find_servers(roles: :pg).size > 0 + pg_params = "-p #{pg_port}" + check_user = %Q[#{sudo} -u postgres psql #{pg_params} postgres -c "select * from pg_user where usename='#{pg_user}'" | grep -c '#{pg_user}'] + add_user = %Q[#{sudo} su postgres -c "createuser -SREd #{pg_params} #{pg_user}"] + run "#{check_user} || #{add_user}" + run %Q{#{sudo} -u postgres psql #{pg_params} -c "alter user #{pg_user} with password '#{pg_password}'" } + end end desc "Create database for application" task :create_database, roles: :pg do - if pg_create_db - run %Q{#{sudo} -u postgres psql -c "create database #{pg_database} owner #{pg_user};"} + if find_servers(roles: :pg).size > 0 + if pg_create_db + run %Q{#{sudo} -u postgres psql -c "create database #{pg_database} owner #{pg_user};"} + end end end - if find_servers(roles: :pg).size > 0 - after "deploy:setup", "kapify:pg:create_user" - after "deploy:setup", "kapify:pg:create_database" - end + after "deploy:setup", "kapify:pg:create_user" + after "deploy:setup", "kapify:pg:create_database" desc "Generate the database.yml configuration file." task :setup, roles: [:app, :resque_worker] do run "mkdir -p #{shared_path}/config" kapify_template("pg", "database.yml.erb", "#{shared_path}/config/database.yml")