Sunday, January 31, 2010

A Look at the New DotNetMigrations

One aspect of .Net that a lot of people struggle with is how to manage database changes.  If anyone has looked beyond .Net into the realms of Ruby on Rails or Python's Django project, database management is one of the first things that becomes obviously different.  Thankfully, there's been a number of migration utilities that have been ported or recreated in the .Net world.  After trying out a couple of them, I began to notice that there was a wide variety of how each attempt to accomplish this pain point.  Some require IronRuby scripting, many use a custom C# DSL, and some use external build utilities like NAnt to fully manage the changes.  One that I was introduced to by a friend and began to really enjoy was DotNetMigrations - an OSS project over at CodePlex.

An Overview of DotNetMigrations

DotNetMigrations started as an OSS project over at CodePlex by Joshua Poehls in early 2008 when he liked what he saw in Ruby on Rails and wished there was a sql script-based version of such a utility in .Net.  Unlike Rails' migration strategy which used a DSL written in Ruby to do all of the database object changes, DotNetMigrations was focused around native Sql scripts that would be read and executed by the migration engine.  As the project evolved, new commands were added and updates to the Rails platform's migration strategy were also made to DotNetMigrations.  Soon, it was obvious that DotNetMigrations had a lot of potential when it comes to new commands and other things.  I ended up joining the project in mid 2009 to make some updates and add some commands that I required for a project I was using it on.

After my project was finishing up, I ended up beginning to think of ways to make the application easier to maintain.  After some conversations with Joshua about this, we decided to go ahead with rewrite with the goals of making it easier to maintain and extend while keeping the same spirit which it was started in.  This past weekend, the finishing touches were placed on the rewritten code and a new release was established with some great features.

Extending DotNetMigrations Thanks to MEF

Any reader of this blog knows that I've been addicted to MEF these past few months.  When I looked at the architecture of DotNetMigrations and the goals of such, the decision to use MEF was an obvious one.  MEF provides the ability to not only extend but also compose internal components of an application.  One of the things we wanted to do was allow other people to create new commands that fit their needs without requiring them to recompile the application's source.  MEF allowed us to do such for external commands and because of such, we also turned all internal commands to conform to the same contracts. 

In addition to the command aspect of DotNetMigration, we also changed the way messages could be logged.  In the older versions of the application, it acted like a standard console application with all messages being output to the console application window.  This works for many scenarios; however, if you needed a "silent" program for your task scheduler or wanted to log all messages to a text file, you'd have to do a lot of additional work with the source code or pipe the command to the text file at the command line.  Through using MEF and the custom configurable type catalog, creating new logs becomes easy as well as being able to utilize one or many different logging mechanisms.

What Else Is New?

In addition to the core code being rewritten to leverage MEF, we also launched the DotNetMigrations-Contrib project.  The focus of this project was to allow others to suggest and share new logs and commands they have written.  The components found in this project also will help allow companies who are locked into specific versions of software upgrade with new commands without having to upgrade the core app.  As time passes in, some elements from the Contrib project may find their way into the core application; however, things are just starting for now.


As new features and such are added to each project, I'm sure I'll be talking about them here.  Until then, feel free to head over to the CodePlex projects' sites and check it out for yourself. 

Shout it

No comments:

Post a Comment