1

I'm writing an application with Ruby on Rails that will take CSV files and migrate data into postgresql databases, however, all of my data is stored as .SQL files or as databases on an MS SQL 2008 server.

I'm wondering if it's possible to write a simple Ruby on Rails script and generate a CSV file from an SQL file/MS SQL database.

Thanks in advance.

user1722960
  • 103
  • 1
  • 5
  • maybe you mean simple `ruby` script? – Roman Kiselenko Jul 03 '14 at 16:46
  • Maybe this question can help you: http://stackoverflow.com/questions/1517635/save-postgres-sql-output-to-csv-file?rq=1 – MrYoshiji Jul 03 '14 at 16:52
  • You cant make Rails read directly from a MS SQL file without going through a MS SQL Server. The easiest solution might be to export the tables from a MS SQL server and then import those CSV files into the new postgres. – Arctodus Jul 03 '14 at 17:10
  • This [here](http://stackoverflow.com/questions/3169220/export-query-result-to-csv-file-in-sql-server-2008) should help you – Anthony Jul 03 '14 at 17:12

1 Answers1

2

I linked you to a SO thread that will help you get the CSV's exported (see the link here for ease). From there you can use your db/seed.rb file and do something like

FasterCSV.foreach("filename") do |row|
  User.create(name: row[0], email: row[1])
end

From there you can simply run rake db:seed

Community
  • 1
  • 1
Anthony
  • 15,435
  • 4
  • 39
  • 69