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

前端 未结 2 741
心在旅途
心在旅途 2021-02-09 18:25

heroku run rake db:migrate works fine to alter the structure of the production database:

Migrating to CreateUsers (20120318090252)
Migrating to AddI         


        
相关标签:
2条回答
  • 2021-02-09 19:07

    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.

    0 讨论(0)
  • 2021-02-09 19:12

    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!

    0 讨论(0)
提交回复
热议问题