如何填充生产数据库(heroku)与开发数据? (Rails) [英] How to populate production database (heroku) with development data? (Rails)

查看:352
本文介绍了如何填充生产数据库(heroku)与开发数据? (Rails)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

heroku run rake db:migrate 可以改变生产数据库的结构:

 迁移到CreateUsers(20120318090252)
迁移到AddIndexToUsersEmail(20120319191315)
迁移到AddPasswordDigestToUsers(20120319194632)
迁移到AddRememberTokenToUsers(20120323142854)

但是我添加到我的本地开发数据库的数据没有上传到



这是正常的,还是有办法使两个数据库匹配?

提前感谢。

解决方案

迁移可以处理结构(模式)和数据,但一旦滚动,在大多数情况下,您的生产数据是规范的信息来源。如果需要设置数据库的数据,例如列表(Mastercard,Visa,Amex)或引导数据(例如设置管理员用户),这可以在seeds.rb文件中。它创建数据库(模式和内容)的副本并自动应用它 - 这通常是一次性的。



(转到其他方向 - 将生产数据库复制到QA或开发实例是一个常见的用例。首先,你可能会认为:Rails应该能够这样做,但是复制一个典型的生产数据库可能会出现问题。最重要的是:复制具有用户信息的生产数据库是一个重大的安全风险;任何复制操作应该至少使用户匿名第二个问题只是数据库大小:生产数据库通常是有用的,生活性能问题或其他边缘情况,但任何大型数据库将最终需要很长时间来复制,并且高度依赖于您使用的具体数据库和权限)



简而言之,Rails在迁移中做了正确的事:假设结构更新可以,但是需要你填充数据。希望这有助于!


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

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

But the entries, the data I have added to my local development database haven't been uploaded to the heroku production database.

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

Thanks in advance.

解决方案

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!

这篇关于如何填充生产数据库(heroku)与开发数据? (Rails)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆