Sha256: 4aedbc0ec08d71b6d33d50663a5423d269e5daa78158b158365771e03a9275ad

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

Standup.script :node do
  self.description = 'Download Rails application database from node to local server'
  
  def run
    in_temp_dir do |dir|
      su_exec 'postgres', "pg_dump -c #{scripts.webapp.db_name} > dump.sql"
      local_exec "mkdir -p tmp/db"
      download "#{dir}/dump.sql",
               :to => 'tmp/db/dump.sql',
               :sudo => true
    end
    
    bootstrap_db
    
    local_exec "psql #{scripts.webapp.db_name} < tmp/db/dump.sql"
  end
  
  def bootstrap_db
    unless exec_sql("select * from pg_user where usename = 'webapp'") =~ /1 row/
      exec_sql "create user webapp with password 'webapp'"
    end
    
    unless exec_sql("select * from pg_database where datname = '#{scripts.webapp.db_name}'") =~ /1 row/
      exec_sql "create database #{scripts.webapp.db_name} with owner webapp"
    end
  end
  
  def exec_sql sql, db_name = 'postgres'
    local_exec "psql #{db_name} -c \"#{sql}\""
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
standup-0.3.9 scripts/download_db.rb