Heroku – connect to different database and transfer data to current environment

If you run into a situation where you’ve been developing an application in a live heroku development environment and have entered a substantial amount of live data that you don’t want to reenter into your live production environment, then connecting to your development instance’s database and retrieving the specific data you are interested in might help. To do this, you can use the following snippet within your production environment’s console:


ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:host=>"your-host",
:database=>"your-database",
:username=>"your-username",
:port =>5432,
:password=>"your-password"
)

This will allow you to interact with the staging environment within your production console to retrieve specific data. You can then reconnect to your current environment’s DB with the following snippet:

ActiveRecord::Base.establish_connection :production

Where you can then use the data you just retrieved to update your production models.

Leave a Reply

Your email address will not be published. Required fields are marked *