Code Templates for MigratorDotNet

March 4, 2010

UPDATE: A newer version of this code is available here

I’ve been hacking around with database migrations and decided to give MigratorDotNet a go. The first problem I found was that I had to manually number the migrations. The trick of using the migration attribute with the current date and time formatted as yyyyMMddhhssfff works a charm, but is a pain to type more than once.

So to solve the problem I’ve created a code template that gives you something like this as a shell:

using System.Data;
using Migrator.Framework;

namespace MigrationLibrary
{
    [Migration(201003040752265)]
    public class Migration1 : Migration
    {
        public override void Up()
        {
            throw new System.NotImplementedException();
        }

        public override void Down()
        {
            throw new System.NotImplementedException();
        }
    }
}

To install it you need to do a couple of things, take the dll from in here and register it in your GAC and then take this zip and drop it into \Visual Studio 2010\Templates\ItemTemplates\Visual C#. Restart Visual studio and you can now add a migration from the new item menu.

I’ve only tried this in visual studio 2010 and have done no real testing. License wise, let people know I wrote it. If it breaks your machine, steals your financial identity, runs off with your wife and then crashes your car into a wall, it’s your own fault for running code you found on the internet. You have been warned.

Discussion, links, and tweets

comments powered by Disqus

I'm a developer at Purplebricks and I sporadicaly tweet here. These posts in no way represent the views of my employeer.