Data migration from php mysql database to rails pg database

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.

First are you sure you need to do this? Rails will support mysql as
well as postgres.

Assuming you do need to do it then I suggest googling for
move database from mysql to postgres
which should get you going.

Colin

Usually you will have access to something like phpMyAdmin or something similar where you can output the data as an .sql file (or whatever best suits the import requirements)
Then import as required.

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