Skip to content

Instantly share code, notes, and snippets.

@jbarnette
Created August 2, 2011 17:14
Show Gist options
  • Save jbarnette/1120688 to your computer and use it in GitHub Desktop.
Save jbarnette/1120688 to your computer and use it in GitHub Desktop.
namespace :db do
desc "Replace the local dev DB with a copy from Heroku."
task :pull, [:src, :dest] do |t, args|
abort "Only in dev." unless ENV.development?
src = args.src || "heroku-app-name"
dest = args.dest || "local-db-name"
restore = "pg_restore -x -O -d #{dest}"
url = "heroku pgbackups:url --app #{src}"
sh "(psql -l | grep #{dest}) && dropdb #{dest} || true"
sh "createdb #{dest} && (curl --silent `#{url}` | #{restore})"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment