Sha256: ddf2a1cf57513cb0c401a7a8945d735acea0d935cd0d250f5dffc3471ec30637

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 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)}
  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)} 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

6 entries across 6 versions & 1 rubygems

Version Path
teleporter-2.0.10 lib/generators/teleport/templates/capistrano/tasks/setup_db.rake
teleporter-2.0.9 lib/generators/teleport/templates/capistrano/tasks/setup_db.rake
teleporter-2.0.8 lib/generators/teleport/templates/capistrano/tasks/setup_db.rake
teleporter-2.0.7 lib/generators/teleport/templates/capistrano/tasks/setup_db.rake
teleporter-2.0.6 lib/generators/teleport/templates/capistrano/tasks/setup_db.rake
teleporter-2.0.4 lib/generators/teleport/templates/capistrano/tasks/setup_db.rake