namespace Infrastructure.DataAccess.UsersMigrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Latest : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.AspNetRoles",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Name = c.String(nullable: false, maxLength: 256),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.Name, unique: true, name: "RoleNameIndex");
            
            CreateTable(
                "dbo.AspNetUserRoles",
                c => new
                    {
                        UserId = c.String(nullable: false, maxLength: 128),
                        RoleId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.UserId, t.RoleId })
                .ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.StepResultDefinition",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        TestCaseID = c.Int(nullable: false),
                        Order = c.Int(nullable: false),
                        Step = c.String(),
                        Result = c.String(),
                        DateCreated = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.TestCase", t => t.TestCaseID, cascadeDelete: true)
                .Index(t => t.TestCaseID);
            
            CreateTable(
                "dbo.TestCase",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Title = c.String(),
                        Description = c.String(),
                        Prerequsity = c.String(),
                        CreatorID = c.String(nullable: false, maxLength: 128),
                        EditorID = c.String(maxLength: 128),
                        ProjectID = c.Int(nullable: false),
                        DateCreated = c.DateTime(nullable: false),
                        DateUpdated = c.DateTime(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.AspNetUsers", t => t.CreatorID, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.EditorID)
                .ForeignKey("dbo.TestProject", t => t.ProjectID, cascadeDelete: true)
                .Index(t => t.CreatorID)
                .Index(t => t.EditorID)
                .Index(t => t.ProjectID);
            
            CreateTable(
                "dbo.AspNetUsers",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Email = c.String(maxLength: 256),
                        EmailConfirmed = c.Boolean(nullable: false),
                        PasswordHash = c.String(),
                        SecurityStamp = c.String(),
                        PhoneNumber = c.String(),
                        PhoneNumberConfirmed = c.Boolean(nullable: false),
                        TwoFactorEnabled = c.Boolean(nullable: false),
                        LockoutEndDateUtc = c.DateTime(),
                        LockoutEnabled = c.Boolean(nullable: false),
                        AccessFailedCount = c.Int(nullable: false),
                        UserName = c.String(nullable: false, maxLength: 256),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.UserName, unique: true, name: "UserNameIndex");
            
            CreateTable(
                "dbo.AspNetUserClaims",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserId = c.String(nullable: false, maxLength: 128),
                        ClaimType = c.String(),
                        ClaimValue = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.AspNetUserLogins",
                c => new
                    {
                        LoginProvider = c.String(nullable: false, maxLength: 128),
                        ProviderKey = c.String(nullable: false, maxLength: 128),
                        UserId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.TestProject",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Description = c.String(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.TestPlan",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        CreatorID = c.String(maxLength: 128),
                        ProductVersion = c.String(),
                        ProjectID = c.Int(nullable: false),
                        DateCreated = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.AspNetUsers", t => t.CreatorID)
                .ForeignKey("dbo.TestProject", t => t.ProjectID, cascadeDelete: true)
                .Index(t => t.CreatorID)
                .Index(t => t.ProjectID);
            
            CreateTable(
                "dbo.TestCaseTestPlan",
                c => new
                    {
                        TestCaseID = c.Int(nullable: false),
                        TestProjectID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.TestCaseID, t.TestProjectID })
                .ForeignKey("dbo.TestPlan", t => t.TestCaseID)
                .ForeignKey("dbo.TestCase", t => t.TestProjectID)
                .Index(t => t.TestCaseID)
                .Index(t => t.TestProjectID);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.TestCaseTestPlan", "TestProjectID", "dbo.TestCase");
            DropForeignKey("dbo.TestCaseTestPlan", "TestCaseID", "dbo.TestPlan");
            DropForeignKey("dbo.TestPlan", "ProjectID", "dbo.TestProject");
            DropForeignKey("dbo.TestPlan", "CreatorID", "dbo.AspNetUsers");
            DropForeignKey("dbo.StepResultDefinition", "TestCaseID", "dbo.TestCase");
            DropForeignKey("dbo.TestCase", "ProjectID", "dbo.TestProject");
            DropForeignKey("dbo.TestCase", "EditorID", "dbo.AspNetUsers");
            DropForeignKey("dbo.TestCase", "CreatorID", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
            DropIndex("dbo.TestCaseTestPlan", new[] { "TestProjectID" });
            DropIndex("dbo.TestCaseTestPlan", new[] { "TestCaseID" });
            DropIndex("dbo.TestPlan", new[] { "ProjectID" });
            DropIndex("dbo.TestPlan", new[] { "CreatorID" });
            DropIndex("dbo.AspNetUserLogins", new[] { "UserId" });
            DropIndex("dbo.AspNetUserClaims", new[] { "UserId" });
            DropIndex("dbo.AspNetUsers", "UserNameIndex");
            DropIndex("dbo.TestCase", new[] { "ProjectID" });
            DropIndex("dbo.TestCase", new[] { "EditorID" });
            DropIndex("dbo.TestCase", new[] { "CreatorID" });
            DropIndex("dbo.StepResultDefinition", new[] { "TestCaseID" });
            DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" });
            DropIndex("dbo.AspNetUserRoles", new[] { "UserId" });
            DropIndex("dbo.AspNetRoles", "RoleNameIndex");
            DropTable("dbo.TestCaseTestPlan");
            DropTable("dbo.TestPlan");
            DropTable("dbo.TestProject");
            DropTable("dbo.AspNetUserLogins");
            DropTable("dbo.AspNetUserClaims");
            DropTable("dbo.AspNetUsers");
            DropTable("dbo.TestCase");
            DropTable("dbo.StepResultDefinition");
            DropTable("dbo.AspNetUserRoles");
            DropTable("dbo.AspNetRoles");
        }
    }
}
