Skip to content

Instantly share code, notes, and snippets.

@ErvalhouS
Created March 14, 2017 09:50
Show Gist options
  • Save ErvalhouS/1446da34c7476ba488a973370f41a4d7 to your computer and use it in GitHub Desktop.
Save ErvalhouS/1446da34c7476ba488a973370f41a4d7 to your computer and use it in GitHub Desktop.
Get latest Heroku database state, dump and apply on localhost Postgres
namespace :latest do
desc "rake 'latest:db' Get last state from the production database"
task db: :environment do
Rake::Task["db:drop"].execute
Rake::Task["db:create"].execute
system( "heroku pg:backups:capture --app <YOUR APP NAME>" )
system( "curl -o latest.dump `heroku pg:backups public-url`" )
system( "pg_restore --verbose --clean --no-acl --no-owner -d <YOUR DEVELOPMENT DATABSE NAME> latest.dump" )
Rake::Task["db:migrate"].execute
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment