将开发数据合并到生产数据中

发布于 2024-10-30 01:16:46 字数 206 浏览 3 评论 0原文

我们上周部署了一个应用程序。问题是我们有一些开发数据想要迁移到生产中,但生产数据库已在使用中。所以仅仅导入和导出SQL就会带来ID不再匹配的问题。

现在,我考虑过将所有数据立即加载到基础对象中,但不存在单一基础对象这样的东西。有四个对象仅具有 has_many 关联,而许多对象则具有多个belongs_to 关联。

还有其他导出和导入方法可以用来实现我们想要的吗?

We've deployed an application last week. The problem is that we have some development data that we'd like to migrate to production, but the production database is already in use. So just importing and exporting SQL will pose the problem that the IDs won't match anymore.

Now, I've thought about eager loading all data into base objects, but there's no such thing as one base object. There are four objects with only has_many associations and a lot of objects with multiple belongs_to associations.

Is there any other method of exporting and importing that we could use to achieve what we want?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

°如果伤别离去 2024-11-06 01:16:46

一种方法可能是将开发数据转储到 yaml(这个插件可以做到这一点,并且可能还有其他方法可以做到这一点),然后使用 db/seeds.rb 编写一个加载其内容的脚本,并使用 Rails 模型在生产数据库上使用 rake db:seed

rake db:seed 重新创建它们,rake db:seed 不会软管您的数据(它只是加载db/seeds.rb,请参阅源 此处此处 ),但请务必在执行任何操作之前备份数据:)

我建议先使用沙箱应用程序和数据库克隆,然后再继续在生产中运行它。

One way might be to dump the dev data to yaml (this plugin does that and there are probably others that will do the trick), and then use db/seeds.rb to write a script loading its contents and using rails models to recreate them on the production db with rake db:seed

rake db:seed won't hose your data (it just loads db/seeds.rb, see the source here and here), but be sure to backup your data before anything :)

I'd suggest playing with a sandbox app and db clone before going ahead and running this on production.

夜深人未静 2024-11-06 01:16:46

将开发数据导出为 CSV、yaml、XML 或您想要使用的任何格式。然后您可以选择要执行的操作:

如果仅导入数据一次,则可以使用迁移从指定文件加载数据。当您将其签入源代码管理时,请务必将文件包含在迁移中。

使用控制台(脚本/控制台制作)加载数据并手动输入命令。这可能是一种更好的方法,因为您可以检查正在输入的数据并根据需要进行调整。

如果您打算多次执行此操作,则编写一个 rake 任务,当给定文件名或其他标识符时,将数据加载到数据库中。

Export the development data as CSV, yaml, XML, or whatever format you want to use for this. Then you have a choice of what to do:

If only importing the data once then you can use a migration to load the data from the specified files. Be sure to include the files with the migration when you check it in to source control.

Load the data using the console (script/console production) and entering the commands manually. This might be a nicer way since you can examine the data that's going in and adjust as necessary.

If you're going to be doing this more then once then write a rake task that when given a filename or other identifier load the data into the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文