Skip to content

Instantly share code, notes, and snippets.

@Maarten88
Last active December 17, 2015 20:48
Show Gist options
  • Save Maarten88/5669837 to your computer and use it in GitHub Desktop.
Save Maarten88/5669837 to your computer and use it in GitHub Desktop.
FluentMigrator Migration that creates the schema for WebPages SimpleMembership with OAuth
using System;
using FluentMigrator;
namespace Auction.Web.Domain.Migrations
{
[Migration(2)]
public class UserProfile : Migration
{
public override void Up()
{
Create.Table("UserProfile")
.WithColumn("UserId").AsInt32().Identity().PrimaryKey()
.WithColumn("UserName").AsString(100).NotNullable().Unique();
Create.Table("webpages_Roles")
.WithColumn("RoleId").AsInt32().NotNullable().PrimaryKey().Identity()
.WithColumn("RoleName").AsString(256).NotNullable().Unique();
Create.Table("webpages_UsersInRoles")
.WithColumn("UserId").AsInt32().NotNullable().ForeignKey("fk_UsersInRole_UserId", "UserProfile", "UserId")
.WithColumn("RoleId").AsInt32().NotNullable().ForeignKey("fk_UsersInRole_RoleId", "webpages_Roles", "RoleId");
Create.PrimaryKey("pk_webpages_UsersInRoles").OnTable("webpages_UsersInRoles").Columns(new[] { "UserId", "RoleId" });
Create.Table("webpages_Membership")
.WithColumn("UserId").AsInt32().NotNullable().PrimaryKey().ForeignKey("fk__Membership_UserId", "UserProfile", "UserId")
.WithColumn("CreateDate").AsDateTime()
.WithColumn("ConfirmationToken").AsString(128).Nullable()
.WithColumn("IsConfirmed").AsBoolean().WithDefaultValue(0)
.WithColumn("LastPasswordFailureDate").AsDateTime().Nullable()
.WithColumn("PasswordFailuresSinceLastSuccess").AsInt32().NotNullable().WithDefaultValue(0)
.WithColumn("Password").AsString(128).NotNullable()
.WithColumn("PasswordChangedDate").AsDateTime().Nullable()
.WithColumn("PasswordSalt").AsString(128).NotNullable()
.WithColumn("PasswordVerificationToken").AsString(128).Nullable()
.WithColumn("PasswordVerificationTokenExpirationDate").AsDateTime().Nullable();
Create.Table("webpages_OAuthMembership")
.WithColumn("Provider").AsString(30).NotNullable()
.WithColumn("ProviderUserId").AsString(100).NotNullable()
.WithColumn("UserId").AsInt32().NotNullable().ForeignKey("fk_OAuthMembership_UserId", "UserProfile", "UserId");
Create.PrimaryKey("pk_webpages_OAuthMembership").OnTable("webpages_OAuthMembership").Columns(new[] { "Provider", "ProviderUserId" });
Create.Table("webpages_OAuthToken")
.WithColumn("Token").AsString(100).NotNullable().PrimaryKey()
.WithColumn("Secret").AsString(100).NotNullable();
}
public override void Down()
{
Delete.Table("webpages_OAuthToken");
Delete.Table("webpages_OAuthMembership");
Delete.Table("webpages_UsersInRoles");
Delete.Table("webpages_Roles");
Delete.Table("webpages_Membership");
Delete.Table("UserProfile");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment