Sha256: fe7ccfaf7e5bba38ed2f322e931cf8c335bf564898464944aee21d6732b299d4

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

namespace :deploy do
  task :setup_db do

    on roles(:app) do
      db_adapter = ask1 %Q{ Choose database adapter:
1. postgresql
2. mysql2 }

      db_adapter = case db_adapter
                   when /1/
                     'postgresql'
                   when /2/
                     'mysql2'
                   end


      ask(:db_password, 'Type database password:')

      database_content = %Q{#{fetch(:rails_env)}
  adapter: #{db_adapter}
  timeout: 5000
  encoding: utf8
  reconnect: false
  database: #{fetch(:application)}_#{fetch(:rails_env)}
  pool: 5
  username: #{fetch(:deploy_user)}
  password: #{fetch(:db_password)}
  host:
  port: 5432
  }


  database_content = StringIO.new(database_content)
  upload! database_content, "#{shared_path}/config/database.yml"

    begin
      execute :whoami
      execute %Q{echo "CREATE ROLE #{fetch(:deploy_user)} PASSWORD '#{fetch(:db_password)}' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;" | sudo -u postgres psql}
    rescue Exception
    end
    begin
      execute :sudo, '/etc/init.d/postgresql restart'
      sleep 3
    rescue Exception
    end
    begin
      execute %Q{echo "CREATE DATABASE #{fetch(:application)}_#{fetch(:rails_env)} WITH OWNER #{fetch(:deploy_user)} ENCODING 'UTF8';" | sudo -u postgres psql}
    rescue Exception
    end
    end
  end
end

def ask1(question)
  puts question
  $stdin.gets.chomp
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
teleporter-1.2.2 lib/generators/initial/templates/capistrano/tasks/setup_db.rake