namespace CARRE_DSS2.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class first : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Observables",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Node = c.String(),
                        Name = c.String(),
                        DataType = c.String(),
                        Unit = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.RiskElements",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Node = c.String(),
                        Name = c.String(),
                        Expression = c.String(),
                        Type = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.RiskFactors",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Node = c.String(),
                        Title = c.String(),
                        AssociationType = c.String(),
                        Target_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.RiskElements", t => t.Target_Id)
                .Index(t => t.Target_Id);
            
            CreateTable(
                "dbo.RiskEvidences",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Node = c.String(),
                        Expression = c.String(),
                        RatioValue = c.Double(nullable: false),
                        RatioType = c.String(),
                        ParrentRiskFactor_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.RiskFactors", t => t.ParrentRiskFactor_Id)
                .Index(t => t.ParrentRiskFactor_Id);
            
            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.AspNetUsers",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Prefix = c.String(),
                        Name = c.String(),
                        Surname = c.String(),
                        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.RiskElementObservables",
                c => new
                    {
                        RiskElement_Id = c.Int(nullable: false),
                        Observable_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.RiskElement_Id, t.Observable_Id })
                .ForeignKey("dbo.RiskElements", t => t.RiskElement_Id, cascadeDelete: true)
                .ForeignKey("dbo.Observables", t => t.Observable_Id, cascadeDelete: true)
                .Index(t => t.RiskElement_Id)
                .Index(t => t.Observable_Id);
            
            CreateTable(
                "dbo.RiskEvidenceObservables",
                c => new
                    {
                        RiskEvidence_Id = c.Int(nullable: false),
                        Observable_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.RiskEvidence_Id, t.Observable_Id })
                .ForeignKey("dbo.RiskEvidences", t => t.RiskEvidence_Id, cascadeDelete: true)
                .ForeignKey("dbo.Observables", t => t.Observable_Id, cascadeDelete: true)
                .Index(t => t.RiskEvidence_Id)
                .Index(t => t.Observable_Id);
            
            CreateTable(
                "dbo.RiskFactorRiskElements",
                c => new
                    {
                        RiskFactor_Id = c.Int(nullable: false),
                        RiskElement_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.RiskFactor_Id, t.RiskElement_Id })
                .ForeignKey("dbo.RiskFactors", t => t.RiskFactor_Id, cascadeDelete: true)
                .ForeignKey("dbo.RiskElements", t => t.RiskElement_Id, cascadeDelete: true)
                .Index(t => t.RiskFactor_Id)
                .Index(t => t.RiskElement_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
            DropForeignKey("dbo.RiskFactors", "Target_Id", "dbo.RiskElements");
            DropForeignKey("dbo.RiskFactorRiskElements", "RiskElement_Id", "dbo.RiskElements");
            DropForeignKey("dbo.RiskFactorRiskElements", "RiskFactor_Id", "dbo.RiskFactors");
            DropForeignKey("dbo.RiskEvidences", "ParrentRiskFactor_Id", "dbo.RiskFactors");
            DropForeignKey("dbo.RiskEvidenceObservables", "Observable_Id", "dbo.Observables");
            DropForeignKey("dbo.RiskEvidenceObservables", "RiskEvidence_Id", "dbo.RiskEvidences");
            DropForeignKey("dbo.RiskElementObservables", "Observable_Id", "dbo.Observables");
            DropForeignKey("dbo.RiskElementObservables", "RiskElement_Id", "dbo.RiskElements");
            DropIndex("dbo.RiskFactorRiskElements", new[] { "RiskElement_Id" });
            DropIndex("dbo.RiskFactorRiskElements", new[] { "RiskFactor_Id" });
            DropIndex("dbo.RiskEvidenceObservables", new[] { "Observable_Id" });
            DropIndex("dbo.RiskEvidenceObservables", new[] { "RiskEvidence_Id" });
            DropIndex("dbo.RiskElementObservables", new[] { "Observable_Id" });
            DropIndex("dbo.RiskElementObservables", new[] { "RiskElement_Id" });
            DropIndex("dbo.AspNetUserLogins", new[] { "UserId" });
            DropIndex("dbo.AspNetUserClaims", new[] { "UserId" });
            DropIndex("dbo.AspNetUsers", "UserNameIndex");
            DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" });
            DropIndex("dbo.AspNetUserRoles", new[] { "UserId" });
            DropIndex("dbo.AspNetRoles", "RoleNameIndex");
            DropIndex("dbo.RiskEvidences", new[] { "ParrentRiskFactor_Id" });
            DropIndex("dbo.RiskFactors", new[] { "Target_Id" });
            DropTable("dbo.RiskFactorRiskElements");
            DropTable("dbo.RiskEvidenceObservables");
            DropTable("dbo.RiskElementObservables");
            DropTable("dbo.AspNetUserLogins");
            DropTable("dbo.AspNetUserClaims");
            DropTable("dbo.AspNetUsers");
            DropTable("dbo.AspNetUserRoles");
            DropTable("dbo.AspNetRoles");
            DropTable("dbo.RiskEvidences");
            DropTable("dbo.RiskFactors");
            DropTable("dbo.RiskElements");
            DropTable("dbo.Observables");
        }
    }
}
