Skip to content

Instantly share code, notes, and snippets.

@hunt3ri
Created August 2, 2012 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hunt3ri/3238059 to your computer and use it in GitHub Desktop.
Save hunt3ri/3238059 to your computer and use it in GitHub Desktop.
Sample FluentMigrator migration
using FluentMigrator;
namespace Nant.Builder.Sample.Migrations
{
[Migration(3)]
public class Mig003_CreateUserRoleTable : Migration
{
private const string TableName = "UserRole";
public override void Up()
{
Create.Table(TableName)
.WithColumn("UserId").AsInt32().NotNullable()
.WithColumn("RoleId").AsInt16().NotNullable();
var compKey = new[] { "UserId", "RoleId" };
Create.PrimaryKey("PK_UserRole").OnTable("UserRole").Columns(compKey);
Create.ForeignKey("FK_UserRole_User").FromTable("UserRole").ForeignColumn("UserId").ToTable("User").PrimaryColumn("UserId");
Create.ForeignKey("FK_UserRole_Role").FromTable("UserRole").ForeignColumn("RoleId").ToTable("Role").PrimaryColumn("RoleId");
}
public override void Down()
{
Delete.ForeignKey("FK_UserRole_User").OnTable(TableName);
Delete.ForeignKey("FK_UserRole_Role").OnTable(TableName);
Delete.Table(TableName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment