How to fill in the production database (geroku) with development data? (Rails)

heroku run rake db:migrate works great to change the structure of the production database:

 Migrating to CreateUsers (20120318090252) Migrating to AddIndexToUsersEmail (20120319191315) Migrating to AddPasswordDigestToUsers (20120319194632) Migrating to AddRememberTokenToUsers (20120323142854) 

But the records, the data that I added to my local development database, were not loaded into the heroku production database.

Is this normal, or is there a way to make two databases appropriate?

Thanks in advance.

+6
source share
2 answers

Migrations can process both a structure (scheme) and data, but once you roll, it is assumed that in most cases your production data is a canonical source of information. If there is data necessary for setting up the database, for example, such as lists ("Mastercard, Visa, Amex") or boot data (for example, setting up the administrator), it can be in the file "seed.rb". which makes a copy of the database (schema and content) and automatically applies it - this is usually a one-time thing.

(Moving in the other direction - copying a production database to QA or development instances is a common precedent. At first you might think: Rails should do this. But copying a typical production database may involve the most important ones: copying the production database with information about the user is a significant security risk; any copy operation should at least make users anonymous. The second problem is simply the size of the database: a production database is often useful or even necessary to reproduce real performance problems or other cases, but any large database will ultimately take a long time to replicate and will depend heavily on the specific database you are using and on permissions)

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

+6
source

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

+9
source

Source: https://habr.com/ru/post/911546/


All Articles