Compares Favourably and NAnt, BFF

Posted by Tom on 2010-06-23 16:00

The original plan for Compares Favourably was to integrate it with our build and deployment process. This means we would be alerted to any differences in the database schema between dev and staging or staging and live at each release. In the end I got sidetracked into learning WinForms and to be honest I probably get more use out of the app because of it. However, my original problem still remains - if we do a release with an out-of-date database schema things break. Pages yellowscreen. Clients cry. Burning sulphur rains from the heavens. Around the world albino bulls are born and explode, killing all in the blast radius. It's pretty bad, and completely avoidable.

We use NAnt for builds, and since there is a command line front end for Compares Favourably I could just use <exec>, dump the output to a file and then parse it, but that seems a little bit pedestrian. Especially when the fine people responsible for NAnt make it so easy to write plugins.

As of revision 48 the ComparesFavourably NAnt task is in the SVN repository. In order to use it from a NAnt build script you will need to do one of the following:

Once that's done you can run Compares Favourably from within NAnt using the following:

<ComparesFavourably 
    settingsfile="..\etc\SampleProjectFile.cmp" 
    resultproperty="result" 
    verbose="false" 
    failondifferences="false"
/>

Here's a brief explanation of the properties.

Property Type Required Default Description
settingsfile string true N/A This is a path to the Compares Favourably project file to use for the comparison
resultproperty string false N/A The name of the property to fill place results in. The result is a bitfield with bit 0 set if there are differences, bit 1 set if items exist in left but not right, and bit 2 set if items exist in right and not left. So a result of 5 shows that some items are different and others are in the destination database but not the source.
failondifferences bool false false Throw a build error there are any differences as a result of the comparison
verbose bool false false Use this property to output more detailed information as the task runs

I'll do a follow-up post later in the month about how to actually write custom NAnt tasks, but if you're impatient then you can get the code right this very moment in the Subversion repository. Instant gratification!

Questions? Bugs? Comments? Feature requests? I am available on the Internets.