Wednesday, November 10, 2010

SubSonic 3.0's SimpleRepository Auto Migrations - What's the point?

I recently began taking a serious look at SubSonic 3.0 for .NET 3.5. The feature that interested me most is called SimpleRepository and is intended to enable code-first development. It is the primary motivation for trying out SubSonic instead of sticking with my tried and true Linq to SQL workflow of design the DB, update the data context, generate classes using my custom T4 template, and then tweak partial classes. Just writing the steps down makes me tired!

SubSonic's built-in SimpleRepository class provides an implementation of code-first and tweak the database later (a.k.a. auto migrations). Initially I didn't get it, but as I read more and more about how coders are using databases these days, the NoDB concept, MongoDB, etc. etc. it started to sink in. What started to sink in? Well being able to just code, being able to forget about the DB and know that the POCOs I'm creating and changing are being accurately mapped to and retrieved from a magical elf-prince named Database. Of course there will be more to it then just magic like that, but I understand and am perfectly ok with dealing with needs like indexing and production DB migration paths. Those issues are discussions for other posts some other day because they concern the test and production environment and not prototyping/developing.

What's the point of auto migrations?

Ok, so what's the point of a feature called auto migrations that won't automagically migrate my production database from version B to version C? The goal of prototyping/developing is not to migrate my production DB up or down, but to be able to quickly create, experiment with, and refine features. Wouldn't it be nice if I didn't have to go through the endless routine of tweak database, update Linq to SQL datacontext, re-generate classes using my custom T4, dot, dot, dot. This is exactly where SimpleRepository with auto migrations enabled shines: if I make a change to my POCOs and then try working with it and the data it contains the SimpleRepository's auto migration feature steps in and alters the database...I'm guessing, just guessing here, but I think it waves a wand and cries out to the elf-prince named Database, "All Your Database Are Belong To Us", and the elf-prince reorganizes his kingdom accordingly. Crazy!

What's the catch?

Are you catching my drift, feeling my excitement, does it sound to good to be true? Is it? I'm not 100% sure yet, but I'm very close to finding out and when I do I'll create a post and supply some code that proves just how super-duper the tech is, and/or laments what is lacking.

If you already have experience with SubSonic 3.0's auto migration feature please share the love with a comment.

No comments: