Upgrading to NHibernate 0.9

time to read 2 min | 344 words

The upgrade process for NQA is relatively simple, but it took quite some time to figure out the right way to do this.

First, the mapping & configuration editors are not hard coded, this mean that I need some way to configure the editors with the information (what goes where, what is required, etc). Luckily, NHibernate is using Xsd schema files to store the format for the mapping & configuration files. .Net provides a useful tool for us to translate Xsd schema files into code (or datasets) that can be XmlSerialized. The output of this tool (called, imaginatively enough xsd.exe) is close enough to what I need to start working, but it lack some key information (namely, whatever an element or attribute are required or not). The first time I built the editors I first used xsd and then edited those files by hand.

Of course, the very next day the made a change to the schema. Obviously this wasn't going to scale, I took the ideas presented here and built a tool that would take the CodeDom that Xsd's classes generate (before it's written out) and make the neccecary transformations. It was quite fun to write this one, I had to syncronize the Xml tree with the CodeDom tree. So now I simply run a tool on the new schema files and I've the new code to feed the editors.

Second, the libraries need to be updates, which is a simply a file copy.

Third, run the tests and see what breaks. I've about 7 broken tests in the upgrade, there were two main reasons for that, but no functionality was borken in the application itself. There were two reasons for the breaks, the first was that as the schema change, auto-generated fields names also change (for instance, @class.id was  at field Item, now it's on field Item1), so that had to be fixed. The second reason was that NHiberante changed their SQL generation routines to omit the character "_" from the start of fields.

Both issues were easily found and corrected.

All in all, pretty painless procedure.