How can I make my staging and production have the same data? (Heroku)
Asked Answered
N

2

10

I've looked at Heroku's Taps project (http://devcenter.heroku.com/articles/taps) but there's a huge constraint on foreign keys, so I'm uncomfortable with using this.

All I want to do is get my production data safely and put it on my staging app so the two are more closely matched. Advice?

Nearly answered 3/8, 2011 at 17:31 Comment(0)
F
20

Thoughtbot posted this a few weeks ago:

You need the pgbackups addon (free), and use this to transfer from production to staging

heroku addons:add pgbackups --remote staging
heroku addons:add pgbackups --remote production
heroku pgbackups:capture --remote production
heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote production` --remote staging

Gist here: https://gist.github.com/1095522

Edit: Make sure you have your git branches "staging" and "production" pointing to the heroku apps.

git remote add production production_heroku_app
git remote add staging staging_heroku_app
Forman answered 3/8, 2011 at 18:36 Comment(1)
Worked perfectly. The description here - particularly the "Transfers" part - coincides with what you said, too: http://devcenter.heroku.com/articles/pgbackups Thanks again.Nearly
R
3

If your staging app is using Postgre SQL as well, you can export your data as a backup using pgbackup (http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup) and then just copy it into your db folder. If not, you may have to use a conversion tool.

Ronaronal answered 3/8, 2011 at 17:37 Comment(2)
You actually don't even need to copy it into the folder. Once you've installed the pgbackups addon on both apps you can copy the DB backup from one into the other using: heroku pgbackups:restore DATABASE '<url_of_backup>'Reversible
Thanks - I'll be sure to try this out soon :]Nearly

© 2022 - 2024 — McMap. All rights reserved.