Archive for the 'Design' Category

The data model, ah the data model

July 4, 2006

Last night I created the data model. I was expecting some shocks because of the things I was used to. I do this fairly often. Making data models is probably one of the only things for which I consider myself to be a specialist. Browsing through the Rails book and websites, I had come to the conclusion that I would go with the flow. Meaning plural for the table names, lowercase all the way, underscores in between words, the lot. Otherwize I would spend too much time debugging or trying to find out why things didn’t work.

I soon learned that data base modeling tools, conceived back in the 90′s where not build to support the rails model. E.g. I like to give meaningfull names to the relations between entities. My tool then makes a nice sentence like

A ‘Customer’ has 0, 1 or more ‘Order(s)’

Following the rails convention, that would be

A ‘customers’ has 0,1, or more ‘orders(s)’

Well ok, I can live with that.

For the rest I struggeled with the case of the migrating keys. The tool I use helps you to put the key of the parent entity to the child entity. (the customer id field in the orders table). When each key is called ‘id’, and 2 or more tables refer to the orders table, you end up with a lot of ‘id’s. So you need to manually rename the role name of that relation to include the child table name.

Well ok, I can live with that too I guess.

I didn’t even check if maybe my tool had some tweak option to let it conform better with the Rails model. (I am always cutting corners to save some time…) (I did come back later, and helaas, no ‘tweak-to-rails’ option was available)

After a while I found myself concentrating on my model. A soon as there are 6 or 7 boxes on the screen, you need to start to think carefully, which is something most developers often forget. After all they think, nothing is easier than creating 6 or 7 tables. We put that here and that there, and 8 months later they’re struggling to understand what’s in their db. No, think think think. Go to sleep. Open the model and think, think, think again, but harder this time. Only when you feel a certain degree of elegantness, you know you are right. Then think again, and again to improve it.

Follow

Get every new post delivered to your Inbox.