Sha256: 71daac436ba33aefccd72326883d70462dd96d1453b94a007e01c90e74392fde

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# Reload development database
namespace :db do

  # postgresql databases
  namespace :pg do

    desc "Dump the database to a compressed archive"
    task :dump_archive do
      queue! %{
        PGPASSWORD=`grep password #{deploy_to}/shared/config/database.yml | \
          cut -d' ' -f4` \
        pg_dump -O -U #{application} -h localhost #{application}_#{stage} | \
          bzip2 -9 > ~/pg_dump.sql.bz2
      }
    end

    desc "Remove the compressed database archive"
    task :remove_archive do
      queue! "rm -f ~/pg_dump.sql.bz2"
    end

    desc "Reload development database from stage"
    task :clone do
      clone_env = ENV["RAILS_ENV"] || "development"
      local_db  = "#{application}_#{clone_env}"

      commands = [
        "mina db:pg:dump_archive",
        "scp #{user}@#{domain}:~/pg_dump.sql.bz2 tmp/",
        "dropdb #{local_db}",
        "createdb #{local_db}",
        "echo 'restoring pg_dump'",
        "bzcat tmp/pg_dump.sql.bz2 | psql #{local_db} >/dev/null",
        "mina db:pg:remove_archive"
      ]

      system commands.join(" && ")
    end

  end  # pg
end  # db

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
self_systeem-0.1.0 test/dummy_app/lib/recipes/db.rb