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.
5 comments
Comments feed for this article
28 April 2010 at 10:50 pm
Jimbo
Hullo
Thanks for posting this. Exactly what I wanted but didn’t have the skills or time to attempt.
Unfortunately I’ve followed your directions but the item doesn’t appear in the list when I try to add an item to my project.
Do you think you could help me out?
Using VS2010 professional. Windows XP SP3
Thanks
Jim
28 April 2010 at 11:16 pm
Jimbo
Hello
I realised that I was trying to add this Item to a web project. When I try to add a new item to a class library project the item “Migration Template” does appear the in the “Add New Items” list but when I try to add the item I get an error dialog with the message “An Item With This Key Has Already Been Added”
Can you please suggest how I can fix this?
Thanks!
Jim
28 April 2010 at 11:46 pm
Jimbo
Me again
A quick update.
I’m wondering whether the code you’ve written in your RunStarted is not working in my machine or in my locale or something.
From the decompiled version I can only see the following line of code:
replacementsDictionary.Add(“$migrationId$”, string.Format(“{0:yyyyMMddhhssfff}”, DateTime.Now));
and I’m wondering if this line is generating the error message in the previous message I posted.
I don’t mind plugging away at this. How would you feel about sending me the source code. Looks like there’s not much to it, but I’d rather have the code than retype and make errors.
Cheers!
Jim
29 April 2010 at 12:53 am
Jimbo
And again.
Looks like the string format is working fine – I ran a test.
Now I’m stuck.
Cheers!
Jim
29 April 2010 at 6:14 am
ilivewithian
Hi Jimbo,
I did test this with VS2010, but not the RTM. I’ll try and take a look later today (time permitting). I’m happy for you to have the source, again I’ll dig it out later today.
Rob