Ruby on Rails
Wednesday, November 18, 2015
On Tuesday, 17 November 2015 13:08:00 UTC, prashant sirohi wrote:
Hi ,i am a newbie in rails and i have recently got a task on my job to migrate the old data from a php website to new rails website.php website data is in mysql and rails data is in postgres,i cannot find a way in which i can transport the whole data from php to rails provided that there are some extra fields and tables being added in rails database also the field names are different in both tables.
Can someone suggest a way to do this so that i don't have to do it manually.
One possible way would be to export the Mysql tables as CSV files, then import them in to your Rails app's PG database.
Without knowing what your app looks like, I would probably add a rake task that uses Ruby's CSV class to read in each exported table - if you use the "headers: true" option when opening the CSV file you can then refer to each column by name.
I'm assuming you have Rails models for each table - so then you do something like
CSV.foreach 'some/file.csv', headers: true do | row |
person = Person.create! first_name: row['first_name'], last_name: row['last_name'], email: row['email']
end
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9d1f4d70-6a8f-478a-9e77-4ccc0e3fb51f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment