简体   繁体   English

在单独的数据库中用旧的SQL表更新新的SQL表

[英]Updating a new SQL table with an old SQL table in a separate database

I have limited experience with Ruby and Active Record, so this is a little tough for me. 我在Ruby和Active Record方面的经验有限,所以这对我来说有点难。 I need to update a new table in a new database with information still contained in the old table of an old database. 我需要使用仍包含在旧数据库的旧表中的信息来更新新数据库中的新表。 I cannot connect to both databases at the same time. 我无法同时连接到两个数据库。

My thinking is to write a script to grab the information from the old database and dump it to a text file ( text1 ). 我的想法是编写一个脚本以从旧数据库中获取信息并将其转储到文本文件( text1 )。 Then manually switch databases and do the same thing on the new database ( text2 ). 然后,手动切换数据库,并对新数据库( text2 )执行相同的操作。 Then I will compare both text files to output the differences in a new text file ( text3 ). 然后,我将比较两个文本文件,以将差异输出到新的文本文件( text3 )中。 And finally, I will somehow upload this to the new database. 最后,我将以某种方式将其上传到新数据库。 That is my pseudocode, at least. 至少那是我的伪代码。

Does anyone have any suggestions or example scripts of how to do this? 是否有人对此有任何建议或示例脚本? How do I eventually convert the final text file ( text3 ) into an array or datatype that I will be able to use to update the new database table? 最终如何将最终的文本文件( text3 )转换为可用于更新新数据库表的数组或数据类型?

I understand this is a fairly general question, but I would really appreciate the help. 我知道这是一个相当普遍的问题,但是我非常感谢您的帮助。 Examples are great, information is great, resources are great, just anything to help me figure this out. 例子很棒,信息很棒,资源很棒,这一切都可以帮助我弄清楚。

Rails provides ability to connect to multiple databases, so I think it would be better to pass data using ActiveRecord than making some operations through text files in your case. Rails提供了连接到多个数据库的功能,因此我认为使用ActiveRecord传递数据要比通过文本文件进行一些操作更好。 All that you need for that is to create settings files and create appropriate models. 您所需要做的就是创建设置文件并创建适当的模型。 More details you can find here Connecting Rails 3.1 with Multiple Databases 您可以在这里找到更多详细信息, 将Rails 3.1与多个数据库连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM