简体   繁体   中英

How to replace your rails local pg db with the database in production on Heroku?

I have a db locally in my Rails app. The app is alreqady linked to Heroku through git. I want to totally replace my development db with the one in production on Heroku . How do it ? Are there a set of commands I can use locally to do the job for me ?

You can easily do it with help of heroku pg:backups:restore command. see the detail document here . If you do not have any s2 url for dump install ngrok and put your file in public folder and provide that ngrok url of dump. This will help.

There's a Heroku command for that: heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb --app sushi , where you replace each of those arguments with your app's information. ( https://devcenter.heroku.com/articles/heroku-postgresql )

You could write a short rake task to fully replace your local db with Heroku using that command:

lib/tasks/db.rake

desc 'replaces local database with Heroku production database'
task replace_local_with_production: :environment do
  Rake::Task['db:drop'].invoke
  system heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb --app sushi
  Rake::Task['db:migrate'].invoke
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM