Migration for .NET first official release is out and supporting MS SQL Server 2000, MySql 4 and Postgre 8 and fully integrated with Castle Generator.
A migration looks like the following:
[Migration(1)]
public class AddPostTable : Migration
{
public override void Up()
{
Database.AddTable("Post",
new Column("Id", typeof(int), ColumnProperties.PrimaryKeyWithIdentity),
new Column("Title", typeof(string), 50),
new Column("Content", typeof(string), 500),
new Column("PostedAt", typeof(DateTime))
);
}
public override void Down()
{
Database.RemoveTable("Post");
}
}
The Up method is called to create, update, insert, etc. and the Down method is called to revert to an older version.
You can run migration, from a project generated with the monorail command line, with the command:
nant migrate
Or, to migrate to a specific version:
nant migrate -D:version=3
One of the coolest feature, that is not in Rails, is automatic transaction support. All migrations are executed inside a transaction and if an exception is thrown, all changes are rolled back. Note that because MySql only support table-level transaction, modifications to the schema won’t be rolled back.
To use, simply update or install the amazing Castle Generator.
By using this tool you understand that this is a beta release and might include some major issues. If you find some, please report them to in Trac.
Thanks to Kevin and Peter for their hard work, patience and support.
Happy migrating!









22 Comments
September 20, 2006 at 11:02 pm
[...] Marc-André Cournoyer is a damn good hacker. Check his latest addition to his Generator project. I’m seriously considering dropping the “official” scaffolding support, and direct the users to the brand new Generator. [...]
September 21, 2006 at 3:32 am
Wonderful work, mark!
With your work with migrate and generator, monorail rocks!
September 22, 2006 at 3:37 am
This looks amazing, period.
Does this works on MS SQL as well? That one _has_ DDL transaction support.
September 22, 2006 at 7:16 am
Thanks Ayende!
Yes the migrator is working on MySql 4 and upper, MS Sql 2000 (not tested on 2005 but should work) and Postgre 8
MS Sql and Postgre both have DDL transaction support, only MySql hasn’t.
November 16, 2006 at 9:16 pm
[...] Some great hackers like Marc-André, are developing important addins to the project like the database migration tool and the generator. We at Shidix have developed a Perl tool to generate ActiveRecord models from an UML diagram and then I helped Marc-André a little bit to get the web site generator working in Mono, so currently you can generate a web site application from UML even with an AJAX interface!!!. It really lets you gain time, the scaffolding is fantastic. To be honest I must say the I just sent a few patches to Marc, he did the whole work, he is the author, is a talented developer CastleProject has been developed on .Net although I use it on Mono and it is integrated on MS Visual Studio, don’t worry about that. It is pretty easy to make an add-in for MonoDevelop as well, a few months ago my friend René Martín and me started the Castle add-in and we got it working in three hours. Well, it is not complete but Im considering to finish and to release it, just need some spare time. Finally there is another important reason to trust in Castle. Hammet, the main Castle leader which is a seasoned Java and .Net developer has launched CastleStronghold, a company founded to provide professional support, consulting and development to companies using the Castle Project to build their next generation of enterprise applications on .Net or Mono. Congratuluations Hammet !. [...]
January 3, 2007 at 7:04 am
[...] style database migration for .NET Marc has the details on a RoR style database migration for .NET that is wrapped into the Castle Generator project. The Castle Generator project is very [...]
April 6, 2007 at 9:46 am
We need support for Firebird RDBMS.
Where should we start implementing it?
I could not find migration.dll sources in castle repository, so i searched for it in NProject. However, NProjects host QIT.Management.Migrator.dll, which is even more puzzling.
Where does Migration.ddl come from? ?:)
April 6, 2007 at 3:01 pm
http://code.macournoyer.com/migrator
June 24, 2007 at 12:52 pm
Great work Marc-Andre, this is exactly what I’ve been looking for.
Do you know of anyone who has made a tool for retro-generating these from an existing database? We have some dev databases which we need to move to production and I’d like to do it all using scripted migrations if possible. Any suggestions? I could code them all by hand, but it would be a huge amount of work…
June 24, 2007 at 1:14 pm
Hey Matt, glad you like my project.
The SchemaDumper could help you on this: http://code.macournoyer.com/migrator/index.fcgi/browser/trunk/app/core/Tools/SchemaDumper.cs
But from what I can remember, it only supports MySQL for now. You can run it from the Migrator.Console tool with the “dump” options, check the usage by running the console parameterless.
I hope this can help and thanks for the comment!
July 20, 2007 at 2:04 pm
I haven’t read the Mozilla License yet so apologies in advance.
Is there a reason you chose to use Integers for your Migration Numbers on the Migration attribute that is specified on the migration class?
In our situation we have 3 environs (dev, testing, and prod) which may be at various migrations. Say, prod is @ 10 and dev has moved to 15. However we discover that migration 8 has an issue which needs to be fixed with another migration. I cannot add that as 11 and roll that to prod, because prod is not ready to move from 11 thru 15. Its sinful to modify 8 and rerun it.
One way is to skip migration numbers and use 10, 20 etc instead of 10, 11, 12. However if the attribute supported real numbers I can add 8.1 and roll that to dev and prod as needed.
Question: Is it OK to modify the source and make my own dll that handles this situation or is this (real numbers) something you considered and discarded for a reason?
Also, is there a way to name the SchemaInfo table to something more meaningful to our product? Should I make that change too? Could that be passed into as a parameter to the migrator?
Your thoughts will be helpful
thanks
July 20, 2007 at 3:31 pm
Hi Rams,
Using real number is not possible. If you have a version 3.5 schema and migrate it to 4 it will be different from another schema which was already at version 4. The version number is unique to the schema version, you don’t want to break this.
If you want to alter something, add a migration, never ever alter an old one.
I hope this is helful. As for the other points, I don’t understand clearly what you’re trying to acheive. But you could give a look at the Trac site: http://code.macournoyer.com/migrator, some ppl have posted useful patches (which are not applied yet…)
July 24, 2007 at 4:09 pm
Hi, this is exactly what I was looking for. I looked into Rails recently and like the concepts very much. However, I just can’t seem to get used to the syntax of Ruby.
One of the better aspects of RoR is rake and the migrations. It is really easy to get up and running fast and maintain the DB versioned.
On the other hand, I can’t use MonoRail on the current project I’m doing, but I would like to keep the DB versioned. Is there a way to do this and run “nant migrate” in a project that was not “generated with the monorail command”? I have checked out and installed the generator tool.
July 24, 2007 at 8:35 pm
You can use either the builtin console or the NAnt task: http://macournoyer.wordpress.com/2006/10/15/migrate-nant-task/
Glad you like my project Dennis!
July 25, 2007 at 6:47 am
I like it very much, but I’m sure I would like it even more if only I could get it to work without needing anything else from the Castle project. I would like it completely stand alone (except nant). The problem probably is that I don’t know jack about Castle (and frankly I don’t need/want to for now either). I’ll look into the sources and try to find with what minimum setup I can get away with. Thanks Again!
July 25, 2007 at 8:26 am
Migrator doesn’t have any dependencies except for MySql and Postgre libs. Try the NAnt task.
July 25, 2007 at 9:53 am
I was not paying attention. I read the two post too quickly. I did not get the fact you said to check out Migrator from source and build it. Mea culpa!
Stupid I know I’m almost too ashamed to post this…
So after rereading the post carefully and doing as told, it is happily migrating databases to points where no one has gone before. Truly amazing stuff.
Thanks again Marc!!!
July 25, 2007 at 10:20 am
Haha, no problems Dennis! I’m really happy this helps you in your day to day work!
July 31, 2007 at 7:44 am
[...] came a very friendly guy called Marc-André Cournoyer, who I stumbled upon via blogsearch. I saw this post and was [...]
August 30, 2008 at 2:12 pm
I do not believe this
December 29, 2008 at 4:23 pm
Is this project still around? I do not see it anywhere…
March 3, 2009 at 5:26 am
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru