Easily port an existing database to Rails

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

My comfort zone

I today realized that I’ve slipped into a comfort zone – this is bad thing. Comfort zones hinder learning and personal development. Falling into a comfort zone can kill you and turn you into a hypothetical zombie. I’ve moved into a house and got myself a Land Rover and I’m living a comfortable lifestyle – I generally have everything I want and have wanted for the past couple of years. What now? Now I’m bored. Continue reading