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)
Now, to apply my theory and hope it works.
A bit of background info: I’m busy porting Moo Invoicing to Rails as it’s just become too cumbersome to add features to and update in it’s current state. It’s written in CodeIgniter, but the time you save writing something in Rails as compared to your average PHP framework is more than noticeable.
Now, in Moo Invoicing you have invoices and quotes. They’re effectively the same thing, but with some minor differences (due date, payments, etc.) So, instead of having a heap of duplicate code, it makes sense to use the same controllers, models and views for both quotes and invoices. I did pretty much the same thing in CodeIgniter, but rails does much more magic in the background, so to hack it to do your bidding is usually a bad idea and can cause you to loose quite a few “features” the framework provides. Also, being new with Rails, you frequently come to times where you think that what you’re trying to do will be “too advanced” for the framework to handle, and you’ll need to do some actual coding, and more frequently you realize that you’re wrong. Most of the time, the Rails guys have a SUPER easy way out. This is one of those cases – it just wasn’t in any of the Rails guides. Continue reading
Don’t really know if this issue is specific to Lion and ZSH, but upon extracting the ImageMagick binary package (from here) to /usr/local/ on Lion, I couldn’t get it to work as per the instructions on the ImageMagick site. I would just download it or use the Rails gem (rmagick), but since I installed Lion, make doesn’t work any longer and since it’s nearing the end of the month I can’t stand off the bandwidth for the xcode4 download. Continue reading
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