0

I have limited experience with Ruby and Active Record, so this is a little tough for me. 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). Then manually switch databases and do the same thing on the new database (text2). Then I will compare both text files to output the differences in a new text file (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?

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.

Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
jloomy25
  • 3
  • 1

1 Answers1

0

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. 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

Community
  • 1
  • 1
MikeZ
  • 485
  • 4
  • 13
  • Interesting. I will try that but just in case, let's say I really cannot connect to both databases at the same time for some reason...any ideas on how to update the new table? – jloomy25 Mar 15 '14 at 18:16
  • Of course, you are able to create some text or csv files and then merge them using Rails or databases, but it will be more complicated than using the offered approach. So I would suggest finding causes of why you can't connect to the databases at the same time as it's possible using Rails – MikeZ Mar 15 '14 at 18:31
  • Well, the issue is that it isn't my code. I was brought into the project late and told they cannot connect to both databases at the same time. And it's standard Ruby with Active Record but not Rails. I was able to create text files for each data set but I can't get them to compare correctly. And once they are compared and the difference put into a new text file, I'm not sure how to convert that text into an array or datatype that I can work with to upload into the new database. Do you have any ideas for that? – jloomy25 Mar 16 '14 at 16:54
  • ok, actually it is feature of ActiveRecord - http://apidock.com/rails/ActiveRecord/Base/establish_connection/class so it can be used either using rails or without it. But if you don't want to use this approach then I suggest using data in YAML format instead of text format. More info for YAML is there http://strugglingwithruby.blogspot.com/2008/10/yaml.html – MikeZ Mar 16 '14 at 17:08
  • Thanks, I'm sure I'll be able to get it from here. – jloomy25 Mar 16 '14 at 17:22