Push and Pull Databases To and From Heroku
Posted by Morten
Warning: This feature is deprecated; please use pg:pull instead.
A frequent question people ask us is “how do I transfer my database between my local workstation and my Heroku app?”
This is an important question for several reasons. First, you always own your data on Heroku, and we want you to be able to get to it quickly and easily at any time. Also – as you may have noticed from previous posts – we’re obsessive about workflow. Whether you’re debugging an issue with production data or setting up a staging environment, being able to quickly pull/push data between environments is key to a smooth experience.
Previously, we offered yaml_db as a solution. We liked that it was simple and database agnostic, but parsing large YAML files is just too slow. We also wanted something that works with any framework compatible with our Rack-based platform. Ricardo, Blake and Adam came up with Taps, which was released last month as a standalone project. Having collected some quality feedback from the community, we’re now pleased to announce that Taps is officially baked into Heroku, allowing seamless and easy database transfer between Heroku apps and any external environment.
To try it out, install the latest Heroku gem. Then use the “db:pull” command to pull your database down from your Heroku app to your local workstation:
$ heroku db:pull Receiving schema Receiving data 8 tables, 591 records users: 100% |================================| Time: 00:00:00 pages: 100% |================================| Time: 00:00:00 comments: 100% |================================| Time: 00:00:00 tags: 100% |================================| Time: 00:00:00 Receiving indexes Resetting sequences
This loads the schema, data, indexes and sequences of the remote Heroku database down into the local database specified in config/database.yml. You can also specify the destination database using standard URI-syntax:
$ heroku db:pull mysql://root:mypass@localhost/mydb
Because Taps uses ActiveRecord (for schema) and Sequel (for data), it seamlessly transfers between different database vendors. In fact, if you don’t feel like running a local database server, just use SQLite:
$ heroku db:pull sqlite://path/to/my.db
Of course, the syntax for pushing your local database up to Heroku is equally simple:
$ heroku db:push Sending schema Sending data users: 100% |================================| Time: 00:00:00 pages: 100% |================================| Time: 00:00:00 comments: 100% |================================| Time: 00:00:00 tags: 100% |================================| Time: 00:00:00 Sending indexes Resetting sequences
That’s Taps in a nutshell. It’s live right now, so check it out and let us know how you like it. Full docs are available here.