namespace MileageTraker.Web.Migrations
{
    using System.Data.Entity.Migrations;
    
    public partial class AddMembership : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "User",
                c => new
                    {
                        UserId = c.Guid(nullable: false),
                        Username = c.String(nullable: false, maxLength: 64),
                        Email = c.String(nullable: false, maxLength: 64),
                        FullName = c.String(nullable: false, maxLength: 128),
                        Password = c.String(nullable: false, maxLength: 128),
                        Comment = c.String(),
                        IsApproved = c.Boolean(nullable: false),
                        PasswordFailuresSinceLastSuccess = c.Int(nullable: false),
                        LastPasswordFailureDate = c.DateTime(nullable: false),
                        LastActivityDate = c.DateTime(nullable: false),
                        LastLockoutDate = c.DateTime(nullable: false),
                        LastLoginDate = c.DateTime(nullable: false),
                        Created = c.DateTime(nullable: false),
                        IsLockedOut = c.Boolean(nullable: false),
                        LastPasswordChangedDate = c.DateTime(nullable: false),
                        PasswordResetToken = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.UserId)
				.Index(t => t.Username, unique: true)
				.Index(t => t.Email, unique: true);
            
            CreateTable(
                "Role",
                c => new
                    {
                        RoleId = c.Guid(nullable: false),
                        RoleName = c.String(nullable: false),
                        Description = c.String(),
                    })
                .PrimaryKey(t => t.RoleId);
            
            CreateTable(
                "RoleUser",
                c => new
                    {
                        Role_RoleId = c.Guid(nullable: false),
                        User_UserId = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Role_RoleId, t.User_UserId })
                .ForeignKey("Role", t => t.Role_RoleId, cascadeDelete: true)
                .ForeignKey("User", t => t.User_UserId, cascadeDelete: true)
                .Index(t => t.Role_RoleId)
                .Index(t => t.User_UserId);

			Sql(@"INSERT INTO [Role]
				   ([RoleId]
				   ,[RoleName]
				   ,[Description])
				 VALUES
					   ('f5bc8c1f-9e8b-4fd8-87d9-27404d8995d5'
					   ,'Administrator'
					   ,'Administrator'),
					   ('bb3bec25-2a4d-467a-b790-e24b53a54717'
					   ,'Developer'
					   ,'Developer')");

			Sql(@"INSERT INTO [User]
					([UserId]
					,[Username]
					,[Email]
					,[FullName]
					,[Password]
					,[Comment]
					,[IsApproved]
					,[PasswordFailuresSinceLastSuccess]
					,[LastPasswordFailureDate]
					,[LastActivityDate]
					,[LastLockoutDate]
					,[LastLoginDate]
					,[Created]
					,[IsLockedOut]
					,[LastPasswordChangedDate]
					,[PasswordResetToken])
				VALUES
					('33EA9A48-628A-458C-A9C9-FBB318C3CF0E'
					,'james.kolpack'
					,'james.kolpack@gmail.com'
					,'James Kolpack'
					,'AH6VqEzZky4QfexgSwJIgg5gHrjaKGEk7pxUVBZz7X1Vkl31TlCUz9yTxmJN3/IDag=='
					,NULL
					,1
					,0
					,'1753-1-1'
					,'1753-1-1'
					,'1753-1-1'
					,'1753-1-1'
					,GETDATE()
					,0
					,'1753-1-1'
					,NULL)");

			Sql(@"INSERT INTO [RoleUser]
				   ([Role_RoleId]
				   ,[User_UserId])
			 VALUES
				   ('bb3bec25-2a4d-467a-b790-e24b53a54717'
				   ,'33EA9A48-628A-458C-A9C9-FBB318C3CF0E')");
        }
        
        public override void Down()
        {
            DropIndex("RoleUser", new[] { "User_UserId" });
            DropIndex("RoleUser", new[] { "Role_RoleId" });
            DropForeignKey("RoleUser", "User_UserId", "User");
            DropForeignKey("RoleUser", "Role_RoleId", "Role");
            DropTable("RoleUser");
            DropTable("Role");
            DropTable("User");
        }
    }
}
