My favorites | Sign in
Project Logo
                
People details
Project owners:
  nrstott, martin.murphy

Inspired by Ruby on Rails migrations, written in C# & boo, Mite brings the versatile tool of database migrations to the .Net community.

We've implemented migrations in a db agnostic style that makes sane assumptions when information is not provided. Static typing along with a fluent interface makes writing migrations using Mite in any of the CLR .Net Languages a very pleasant experience.

For those not familiar with migrations. Migrations offer a simple way to maintain the version of your db schema through convention. Which does away with managing Sql Scripts or manually managing the database and allows your code/build script to up or down the database to the appropriate schema version for your application.

An example migration:

company = "Company"
employee = "Employee"

up:
    add_table company:
         string "Name", { max_length = 65, unique = true }
    
    add_table employee:
         string "Name", { max_length = 65 }
         int32 "CompanyId"
    
    add_relation "employment", Cardinality.OneToMany, company, employee + ".CompanyId"

down:
    drop_table employee
    drop_table company

Or in C# ...

public class Migration1 : MigrationBase
    {
        public Migration1(IAdapter adapter, string databaseName)
            : base(adapter, databaseName)
        {

        }

        public override uint Version
        {
            get { return 1; }
        }

        protected override void Up()
        {
            
            AddTable("activity_participation",
                    new Int32("registration_id", false),
                    new Int32("activity_id", false)
               );
        }

        protected override void Down()
        {
            DropTable("activity_participation");           
        }
    }

Unless overridden, all tables by default receive a primary key called "Id" that is a 32-bit integer that autoincrements if the DB supports it.

Two local variables are used: company and employee. This is about keeping it DRY. Since the boo based DSL is actually a language, using language features like these local variables and the use of the Cardinality enumeration are possible.

Many of the methods in Mite have smarts. The add_relation method, for example, does not need you to tell it that you want to relate employee.CompanyId to Company.Id. It assumes that you are going to hook up to the primary key unless you otherwise specify.

If you don't like the looks of the DSL, don't worry. Mite migrations can be written in plain old C# as well.

Also, the boo can be written with C# naming conventions instead of the ruby-like ones shown above. The same migration from above could also be written as the following.

company = "Company"
employee = "Employee"

Up:
    AddTable company:
         String "Name", { max_length = 65, unique = true }
    
    AddTable employee:
         String "Name", { max_length = 65 }
         Int32 "CompanyId"
    
    AddRelation "employment", Cardinality.OneToMany, company
Down:
    DropTable employee
    DropTable company

For more information. Subscribe to Nathan's blog here. http://nathan.whiteboard-it.com/









Hosted by Google Code