Sunday, November 27, 2011

MySQL and the inheritance problem

So early on, I had decided to go with MySQL and InnoDB for my database of choice. Recently however I decided I needed to change this. As part of adding an audit trail for the TruSafe Vault, I wanted to inherit multiple encrypted items from a single parent, and add logging to that parent object.

In WebObjects, this means choosing an inheritance model, whether it is Single-table, Horizontal, or Vertical inheritance. I chose the Vertical inheritance model since it closely models after the object model. There may be performance issues later, but it would be a relatively trivial migration to move to the single table model. Horizontal wasn't an option, as it didn't allow for foreign key relationships at the parent level.

This introduced a new problem. MySQL checks all constraints at statement time, not commit time! Coming from the Oracle world, I wasn't used to this. This put a huge dependency on me to order the object creation and saving properly or else things would just fail. With WebObjects hiding much of the inheritance object creation, this became quite difficult.

Rather than peppering my code with various hacks to overcome this, or changing the whole data model to adhere to this limitation, I decided to switch databases. Sounds reasonable, right? Well I didn't have any data, and was a little concerned about the licensing of the MySQL JDBC drivers anyway.

So out with MySQL, and in with Postgresql. 9.1 to be exact. Installed in on my MacBook Air, change the WebObjects database driver from MySQL to Postgresql and off I was. In actuality, it really was that simple.

And because Project Wonder, which is a huge framework built on extending WebObjects, is so wonder-ful, if I did need to change databases, there is a convenient way to do this.

If you plan on doing a WebObjects app, don't do it without Project Wonder and WOLips.

Initial thoughts

TruSafe has always been a little side project for me to do a simple, yet secure, password or note storage mechanism. Ideally it would allow people to store this encrypted on a SaaS platform while sharing it using public/private key mechanisms with people they trust.

I've had a couple of false starts, but recently I've been given a sabbatical from my day job and went to Costa Rica (Playa Coyote to be exact) and decided that as part of my time down here, I want to really get TruSafe going.

Since I'm a better operations engineer than programmer, I decided to use the one programming framework that I know relatively well, so the whole site will be written in WebObjects and deployed to a Linux VPS. And written while drinking La Cerveza de Costa Rica, so this should be interesting :-).