I’m busy porting Moo Invoicing from CodeIgniter to Ruby on Rails, and I’ve come to the point where I need to somehow get the existing MySQL database into the new PostGres database, along with the differing schema. Initially I thought the best way would be to connect to the existing MySQL database from Rails, but I couldn’t find enough information on how to do this. I then settled for an easier way – Convert the MySQL database dump to YAML, load it up in a Rails controller and do everything from there. As of writing, I’ve not yet done what I’m planning to do, but it should go something like this:
1 – Dump the database and convert it to YAML using this PHP library by Jonathan Franzone.
2 – In your Rails controller, open the YAML file:
oldDatabase = YAML.load(File.open("pathtofile.yml"))
3 – And bam, you have an object of your whole database that you can iterate through and create new rows from through Active Record!
oldDatabase.clients.each do |client|
Client.create(:name => client.name)
end
Now, to apply my theory and hope it works.
