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

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

问题描述

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

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)

但是条目,我添加到本地开发数据库的数据还没有上传到heroku生产数据库.

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?

提前致谢.

推荐答案

迁移可以处理结构(模式)和数据,但是一旦你开始滚动,假设在大多数情况下你的生产数据是规范的来源信息.如果需要设置数据库的数据,例如列表(万事达卡、维萨卡、美国运通卡")或引导数据(例如设置管理员用户),则可以进入种子 .rb"文件.没有内置任何内容复制数据库(模式和内容)并自动应用它——这通常是一次性的.

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.

(往 other 方向发展——将生产数据库复制到 QA 或开发实例是一个常见的用例.起初,您可能会认为:Rails 应该能够做到这一点.但是复制一个典型的生产数据库可能充满问题.最重要的是:复制具有用户信息的生产数据库是一个重大的安全风险;任何复制操作至少应该使用户匿名.第二个问题只是数据库大小:生产数据库对于重现现实生活中的性能问题或其他边缘情况通常有用甚至是必要的,但是任何大型数据库最终都会花费很长时间来复制,并且高度依赖于您正在使用的特定数据库以及权限)

(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)

简而言之,Rails 在迁移方面做了正确的事情:假设结构更新是可以的,但需要您填充数据.希望这会有所帮助!

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

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

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