How to populate production database (heroku) with development data? (Rails) How to populate production database (heroku) with development data? (Rails) heroku heroku

How to populate production database (heroku) with development data? (Rails)


This is the normal behavior. rake db:migrate will only create your database structure. If you want to duplicate the data you already have in development on Heroku, use the heroku db:push command, or just use the seeds.rb if you want to initialize the database with some fixed records.


Migrations can handle both structure (schema) and data, but once you're rolling, the assumption is that in most cases your production data is the canonical source of information. If there's data needed to set up the database, for example things like lists ("Mastercard, Visa, Amex) or bootstrapping data (e.g. setting up an admin user) this can go in the "seeds .rb" file. There's nothing built in that makes a copy of a database (schema and content) and automatically applied it -- this would typically be a one-time thing.

(Going the other direction -- copying the production database to QA or development instances is a common use case. At first, you might think: Rails should be able to do this. But copying a typical production database may be fraught with issues. The most important is: copying a production database having user info is a significant security risk; any copy operation should at the very least make users anonymous. A second issue is just database size: a production database is often useful or even necessary to reproduce real-life performance issues or other edge cases, but any large database will end up taking a long time to replicate, and is highly dependent both on the specific database you're using, and on the permissions)

In short, Rails does the right thing with migration: assumes structural updates are OK, but requires you to populate data. Hope this helps!