namespace Question2AnswerMigrater.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ForumCategories",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ParentId = c.Int(),
                        Title = c.String(),
                        Description = c.String(),
                        Url = c.String(),
                        OrderBy = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ForumCategories", t => t.ParentId)
                .Index(t => t.ParentId)
                .Index(t => t.OrderBy);
            
            CreateTable(
                "dbo.ForumPostFlags",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ForumPostId = c.Int(nullable: false),
                        AuthorId = c.String(nullable: false, maxLength: 128),
                        Reason = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers", t => t.AuthorId, cascadeDelete: true)
                .ForeignKey("dbo.ForumPosts", t => t.ForumPostId, cascadeDelete: true)
                .Index(t => t.ForumPostId)
                .Index(t => t.AuthorId);
            
            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.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.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.ForumPosts",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CategoryId = c.Int(),
                        ParentId = c.Int(),
                        Title = c.String(),
                        Content = c.String(),
                        AuthorId = c.String(maxLength: 128),
                        BestChildId = c.Int(),
                        ClosedReason = c.String(),
                        Views = c.Int(nullable: false),
                        LastViewIp = c.String(maxLength: 39),
                        CreatedByIp = c.String(maxLength: 39),
                        LastAction = c.DateTime(),
                        LastActionAuthorId = c.String(maxLength: 128),
                        OldSystemId = c.Int(nullable: false),
                        OldSystemAuthorEmail = c.String(),
                        OldSystemAuthorName = c.String(),
                        IsDeleted = c.Boolean(nullable: false),
                        DeletedOn = c.DateTime(),
                        CreatedOn = c.DateTime(nullable: false),
                        ModifiedOn = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers", t => t.AuthorId)
                .ForeignKey("dbo.ForumPosts", t => t.BestChildId)
                .ForeignKey("dbo.ForumCategories", t => t.CategoryId)
                .ForeignKey("dbo.ForumPosts", t => t.ParentId)
                .ForeignKey("dbo.AspNetUsers", t => t.LastActionAuthorId)
                .Index(t => t.CategoryId)
                .Index(t => t.ParentId)
                .Index(t => t.AuthorId)
                .Index(t => t.BestChildId)
                .Index(t => t.LastAction)
                .Index(t => t.LastActionAuthorId)
                .Index(t => t.IsDeleted);
            
            CreateTable(
                "dbo.ForumWords",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Word = c.String(maxLength: 80),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.Word, unique: true);
            
            CreateTable(
                "dbo.ForumPostVotes",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ForumPostId = c.Int(nullable: false),
                        AuthorId = c.String(maxLength: 128),
                        OldSystemAuthorEmail = c.String(),
                        VoteType = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers", t => t.AuthorId)
                .ForeignKey("dbo.ForumPosts", t => t.ForumPostId, cascadeDelete: true)
                .Index(t => t.ForumPostId)
                .Index(t => t.AuthorId);
            
            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.ForumWordForumPosts",
                c => new
                    {
                        ForumWord_Id = c.Int(nullable: false),
                        ForumPost_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.ForumWord_Id, t.ForumPost_Id })
                .ForeignKey("dbo.ForumWords", t => t.ForumWord_Id, cascadeDelete: true)
                .ForeignKey("dbo.ForumPosts", t => t.ForumPost_Id, cascadeDelete: true)
                .Index(t => t.ForumWord_Id)
                .Index(t => t.ForumPost_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
            DropForeignKey("dbo.ForumPostVotes", "ForumPostId", "dbo.ForumPosts");
            DropForeignKey("dbo.ForumPostVotes", "AuthorId", "dbo.AspNetUsers");
            DropForeignKey("dbo.ForumWordForumPosts", "ForumPost_Id", "dbo.ForumPosts");
            DropForeignKey("dbo.ForumWordForumPosts", "ForumWord_Id", "dbo.ForumWords");
            DropForeignKey("dbo.ForumPosts", "LastActionAuthorId", "dbo.AspNetUsers");
            DropForeignKey("dbo.ForumPostFlags", "ForumPostId", "dbo.ForumPosts");
            DropForeignKey("dbo.ForumPosts", "ParentId", "dbo.ForumPosts");
            DropForeignKey("dbo.ForumPosts", "CategoryId", "dbo.ForumCategories");
            DropForeignKey("dbo.ForumPosts", "BestChildId", "dbo.ForumPosts");
            DropForeignKey("dbo.ForumPosts", "AuthorId", "dbo.AspNetUsers");
            DropForeignKey("dbo.ForumPostFlags", "AuthorId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.ForumCategories", "ParentId", "dbo.ForumCategories");
            DropIndex("dbo.ForumWordForumPosts", new[] { "ForumPost_Id" });
            DropIndex("dbo.ForumWordForumPosts", new[] { "ForumWord_Id" });
            DropIndex("dbo.AspNetRoles", "RoleNameIndex");
            DropIndex("dbo.ForumPostVotes", new[] { "AuthorId" });
            DropIndex("dbo.ForumPostVotes", new[] { "ForumPostId" });
            DropIndex("dbo.ForumWords", new[] { "Word" });
            DropIndex("dbo.ForumPosts", new[] { "IsDeleted" });
            DropIndex("dbo.ForumPosts", new[] { "LastActionAuthorId" });
            DropIndex("dbo.ForumPosts", new[] { "LastAction" });
            DropIndex("dbo.ForumPosts", new[] { "BestChildId" });
            DropIndex("dbo.ForumPosts", new[] { "AuthorId" });
            DropIndex("dbo.ForumPosts", new[] { "ParentId" });
            DropIndex("dbo.ForumPosts", new[] { "CategoryId" });
            DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" });
            DropIndex("dbo.AspNetUserRoles", new[] { "UserId" });
            DropIndex("dbo.AspNetUserLogins", new[] { "UserId" });
            DropIndex("dbo.AspNetUserClaims", new[] { "UserId" });
            DropIndex("dbo.AspNetUsers", "UserNameIndex");
            DropIndex("dbo.ForumPostFlags", new[] { "AuthorId" });
            DropIndex("dbo.ForumPostFlags", new[] { "ForumPostId" });
            DropIndex("dbo.ForumCategories", new[] { "OrderBy" });
            DropIndex("dbo.ForumCategories", new[] { "ParentId" });
            DropTable("dbo.ForumWordForumPosts");
            DropTable("dbo.AspNetRoles");
            DropTable("dbo.ForumPostVotes");
            DropTable("dbo.ForumWords");
            DropTable("dbo.ForumPosts");
            DropTable("dbo.AspNetUserRoles");
            DropTable("dbo.AspNetUserLogins");
            DropTable("dbo.AspNetUserClaims");
            DropTable("dbo.AspNetUsers");
            DropTable("dbo.ForumPostFlags");
            DropTable("dbo.ForumCategories");
        }
    }
}
