Created
August 2, 2012 15:47
-
-
Save hunt3ri/3238059 to your computer and use it in GitHub Desktop.
Sample FluentMigrator migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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