Skip to content
schambers edited this page Sep 14, 2010 · 10 revisions

The basic unit of FM is the Migration abstract class. Your migrations will derive from this class and implement two methods. You also need to define the Migration attribute with a unique identifier.

Commonly, this identifier is just an incrementing value, although the attribute accepts a Int64, some people use a numbered date format such as yyyyMMdd. The significance of this number is for the ordering of your migrations. Lower numbers execute first and then larger. It also provides a way to target a specific migration. Your migration class that you create is where you define the migrations to execute.

Since you define both a TO and FROM for each migration, it’s possible to move forward and backwards in migrations at any point in time. The only caveat is that migrating down is destructive as tables and/or rows are being deleted in the process. Be sure to have a backup first if you want to keep the data.


[Migration(1)]
public class CreateUserTable : Migration
{
    public override void Up()
    {
        Create.Table("Users");
    }

    public override void Down()
    {
        Delete.Table("Users");
    }
}

When you are migrating TO version 1 (if the database is empty for instance), then the migration code in the Up() method will be called creating a table called “Users” in the database.

When you are migrating to a version BEFORE version 1 (for instance version 0), then the migration code in the Down() method will be called deleting the “Users” table from the database.

Diving further into FM, we look at the Fluent Interface to make more useful migrations.

Clone this wiki locally