protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Role",
                columns: table => new
            {
                Id       = table.Column <string>(nullable: false),
                Name     = table.Column <string>(nullable: true),
                CardType = table.Column <int>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Role", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "User",
                columns: table => new
            {
                Id   = table.Column <string>(nullable: false),
                Name = table.Column <string>(nullable: true),
                Sex  = table.Column <int>(nullable: false),
                Age  = table.Column <double>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_User", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "LoginLog",
                columns: table => new
            {
                Id         = table.Column <string>(nullable: false),
                UserId     = table.Column <string>(nullable: true),
                LoginTime  = table.Column <DateTime>(nullable: false),
                LogoutTime = table.Column <DateTime>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_LoginLog", x => x.Id);
                table.ForeignKey(
                    name: "FK_LoginLog_User_UserId",
                    column: x => x.UserId,
                    principalTable: "User",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "OperateLog",
                columns: table => new
            {
                Id      = table.Column <string>(nullable: false),
                UserId1 = table.Column <string>(nullable: true),
                UserId2 = table.Column <string>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_OperateLog", x => x.Id);
                table.ForeignKey(
                    name: "FK_OperateLog_User_UserId1",
                    column: x => x.UserId1,
                    principalTable: "User",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_OperateLog_User_UserId2",
                    column: x => x.UserId2,
                    principalTable: "User",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "UserExtraInfo",
                columns: table => new
            {
                Id      = table.Column <string>(nullable: false),
                UserId  = table.Column <string>(nullable: true),
                Address = table.Column <string>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_UserExtraInfo", x => x.Id);
                table.ForeignKey(
                    name: "FK_UserExtraInfo_User_UserId",
                    column: x => x.UserId,
                    principalTable: "User",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "UserRole",
                columns: table => new
            {
                Id            = table.Column <string>(nullable: false),
                UserIdCurrent = table.Column <string>(nullable: true),
                UserIdParent  = table.Column <string>(nullable: true),
                RoleId        = table.Column <string>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_UserRole", x => x.Id);
                table.ForeignKey(
                    name: "FK_UserRole_Role_RoleId",
                    column: x => x.RoleId,
                    principalTable: "Role",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_UserRole_User_UserIdCurrent",
                    column: x => x.UserIdCurrent,
                    principalTable: "User",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_UserRole_User_UserIdParent",
                    column: x => x.UserIdParent,
                    principalTable: "User",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateIndex(
                name: "IX_LoginLog_UserId",
                table: "LoginLog",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_OperateLog_UserId1",
                table: "OperateLog",
                column: "UserId1");

            migrationBuilder.CreateIndex(
                name: "IX_OperateLog_UserId2",
                table: "OperateLog",
                column: "UserId2");

            migrationBuilder.CreateIndex(
                name: "IX_UserExtraInfo_UserId",
                table: "UserExtraInfo",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_UserRole_RoleId",
                table: "UserRole",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_UserRole_UserIdCurrent",
                table: "UserRole",
                column: "UserIdCurrent");

            migrationBuilder.CreateIndex(
                name: "IX_UserRole_UserIdParent",
                table: "UserRole",
                column: "UserIdParent");
            migrationBuilder.ApplyDatabaseDescription(this);
        }
Esempio n. 2
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Domains",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                ConcurrencyStamp     = table.Column <string>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                SC = table.Column <string>(nullable: true),
                ComplexProperty_C1 = table.Column <string>(nullable: true),
                ComplexProperty_C2 = table.Column <string>(nullable: true),
                ComplexProperty_ComplexProperty2_C3 = table.Column <string>(nullable: true),
                ComplexProperty_ComplexProperty2_C4 = table.Column <string>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Domains", x => x.Id);
            });

            migrationBuilder.CreateTable(
                name: "Menus",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                ConcurrencyStamp     = table.Column <string>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                ParentId             = table.Column <int>(nullable: true),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                MenuIcon_Type        = table.Column <string>(nullable: true),
                MenuIcon_Value       = table.Column <string>(nullable: true),
                Title = table.Column <string>(nullable: true),
                Order = table.Column <short>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Menus", x => x.Id);
                table.ForeignKey(
                    name: "FK_Menus_Menus_ParentId",
                    column: x => x.ParentId,
                    principalTable: "Menus",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "TreeDomains",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                ConcurrencyStamp     = table.Column <string>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                ParentId             = table.Column <int>(nullable: true),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                SampleColumn         = table.Column <string>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_TreeDomains", x => x.Id);
                table.ForeignKey(
                    name: "FK_TreeDomains_TreeDomains_ParentId",
                    column: x => x.ParentId,
                    principalTable: "TreeDomains",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "MenuItems",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                ConcurrencyStamp     = table.Column <string>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                MenuItemIcon_Type    = table.Column <string>(nullable: true),
                MenuItemIcon_Value   = table.Column <string>(nullable: true),
                Title  = table.Column <string>(nullable: true),
                Link   = table.Column <string>(nullable: true),
                Order  = table.Column <short>(nullable: false),
                MenuId = table.Column <int>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_MenuItems", x => x.Id);
                table.ForeignKey(
                    name: "FK_MenuItems_Menus_MenuId",
                    column: x => x.MenuId,
                    principalTable: "Menus",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateIndex(
                name: "IX_MenuItems_MenuId",
                table: "MenuItems",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_Menus_ParentId",
                table: "Menus",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_TreeDomains_ParentId",
                table: "TreeDomains",
                column: "ParentId");

            migrationBuilder.ApplyDatabaseDescription(this);
            migrationBuilder.CreateTreeEntityView(TargetModel.GetEntityTypes());

            #region 创建 MiniProfiler 的分析数据存储表

            var sqls = new StackExchange.Profiling.Storage.SqlServerStorage("").TableCreationScripts;
            foreach (var sql in sqls)
            {
                migrationBuilder.Sql(sql);
            }

            #endregion
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AppUsers",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                UserName           = table.Column <string>(maxLength: 256, nullable: true),
                NormalizedUserName = table.Column <string>(maxLength: 256, nullable: true),
                Email                = table.Column <string>(maxLength: 256, nullable: true),
                NormalizedEmail      = table.Column <string>(maxLength: 256, nullable: true),
                EmailConfirmed       = table.Column <bool>(nullable: false),
                PasswordHash         = table.Column <string>(nullable: true),
                SecurityStamp        = table.Column <string>(nullable: true),
                PhoneNumber          = table.Column <string>(nullable: true),
                PhoneNumberConfirmed = table.Column <bool>(nullable: false),
                TwoFactorEnabled     = table.Column <bool>(nullable: false),
                LockoutEnd           = table.Column <DateTimeOffset>(nullable: true),
                LockoutEnabled       = table.Column <bool>(nullable: false),
                AccessFailedCount    = table.Column <int>(nullable: false),
                ConcurrencyStamp     = table.Column <string>(nullable: true),
                Active               = table.Column <bool>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                Gender               = table.Column <int>(nullable: true),
                InsertOrder          = table.Column <long>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppUsers", x => x.Id);
                table.ForeignKey(
                    name: "FK_AppUsers_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUsers_AppUsers_LastModifierId",
                    column: x => x.LastModifierId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "AppOrganizations",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                ConcurrencyStamp     = table.Column <string>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                ParentId             = table.Column <int>(nullable: true),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                Name        = table.Column <string>(nullable: true),
                Description = table.Column <string>(nullable: true),
                InsertOrder = table.Column <long>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppOrganizations", x => x.Id);
                table.ForeignKey(
                    name: "FK_AppOrganizations_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppOrganizations_AppUsers_LastModifierId",
                    column: x => x.LastModifierId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppOrganizations_AppOrganizations_ParentId",
                    column: x => x.ParentId,
                    principalTable: "AppOrganizations",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "AppRoles",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                Name                 = table.Column <string>(maxLength: 256, nullable: true),
                NormalizedName       = table.Column <string>(maxLength: 256, nullable: true),
                ConcurrencyStamp     = table.Column <string>(nullable: true),
                Description          = table.Column <string>(nullable: true),
                ParentId             = table.Column <int>(nullable: true),
                Active               = table.Column <bool>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                InsertOrder          = table.Column <long>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppRoles", x => x.Id);
                table.ForeignKey(
                    name: "FK_AppRoles_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppRoles_AppUsers_LastModifierId",
                    column: x => x.LastModifierId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppRoles_AppRoles_ParentId",
                    column: x => x.ParentId,
                    principalTable: "AppRoles",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
            });

            migrationBuilder.CreateTable(
                name: "AppUserClaims",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                UserId               = table.Column <int>(nullable: false),
                ClaimType            = table.Column <string>(nullable: true),
                ClaimValue           = table.Column <string>(nullable: true),
                Active               = table.Column <bool>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                ApplicationUserId    = table.Column <int>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppUserClaims", x => x.Id);
                table.ForeignKey(
                    name: "FK_AppUserClaims_AppUsers_ApplicationUserId",
                    column: x => x.ApplicationUserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserClaims_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserClaims_AppUsers_LastModifierId",
                    column: x => x.LastModifierId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserClaims_AppUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AppUserLogins",
                columns: table => new
            {
                LoginProvider       = table.Column <string>(nullable: false),
                ProviderKey         = table.Column <string>(nullable: false),
                ProviderDisplayName = table.Column <string>(nullable: true),
                UserId            = table.Column <int>(nullable: false),
                CreationTime      = table.Column <DateTimeOffset>(nullable: false),
                CreatorId         = table.Column <int>(nullable: true),
                ApplicationUserId = table.Column <int>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppUserLogins", x => new { x.LoginProvider, x.ProviderKey });
                table.ForeignKey(
                    name: "FK_AppUserLogins_AppUsers_ApplicationUserId",
                    column: x => x.ApplicationUserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserLogins_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserLogins_AppUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AppUserTokens",
                columns: table => new
            {
                UserId            = table.Column <int>(nullable: false),
                LoginProvider     = table.Column <string>(nullable: false),
                Name              = table.Column <string>(nullable: false),
                Value             = table.Column <string>(nullable: true),
                CreationTime      = table.Column <DateTimeOffset>(nullable: false),
                CreatorId         = table.Column <int>(nullable: true),
                ApplicationUserId = table.Column <int>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
                table.ForeignKey(
                    name: "FK_AppUserTokens_AppUsers_ApplicationUserId",
                    column: x => x.ApplicationUserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserTokens_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserTokens_AppUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AppUserOrganizations",
                columns: table => new
            {
                UserId            = table.Column <int>(nullable: false),
                OrganizationId    = table.Column <int>(nullable: false),
                CreationTime      = table.Column <DateTimeOffset>(nullable: false),
                CreatorId         = table.Column <int>(nullable: true),
                ApplicationUserId = table.Column <int>(nullable: true),
                OrganizationId1   = table.Column <int>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppUserOrganizations", x => new { x.UserId, x.OrganizationId });
                table.ForeignKey(
                    name: "FK_AppUserOrganizations_AppUsers_ApplicationUserId",
                    column: x => x.ApplicationUserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserOrganizations_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserOrganizations_AppOrganizations_OrganizationId",
                    column: x => x.OrganizationId,
                    principalTable: "AppOrganizations",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
                table.ForeignKey(
                    name: "FK_AppUserOrganizations_AppOrganizations_OrganizationId1",
                    column: x => x.OrganizationId1,
                    principalTable: "AppOrganizations",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserOrganizations_AppUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AppRoleClaims",
                columns: table => new
            {
                Id = table.Column <int>(nullable: false)
                     .Annotation("SqlServer:Identity", "1, 1"),
                RoleId               = table.Column <int>(nullable: false),
                ClaimType            = table.Column <string>(nullable: true),
                ClaimValue           = table.Column <string>(nullable: true),
                Active               = table.Column <bool>(nullable: true),
                IsDeleted            = table.Column <bool>(nullable: false),
                CreationTime         = table.Column <DateTimeOffset>(nullable: false),
                LastModificationTime = table.Column <DateTimeOffset>(nullable: false),
                CreatorId            = table.Column <int>(nullable: true),
                LastModifierId       = table.Column <int>(nullable: true),
                ApplicationRoleId    = table.Column <int>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppRoleClaims", x => x.Id);
                table.ForeignKey(
                    name: "FK_AppRoleClaims_AppRoles_ApplicationRoleId",
                    column: x => x.ApplicationRoleId,
                    principalTable: "AppRoles",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppRoleClaims_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppRoleClaims_AppUsers_LastModifierId",
                    column: x => x.LastModifierId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppRoleClaims_AppRoles_RoleId",
                    column: x => x.RoleId,
                    principalTable: "AppRoles",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "AppUserRoles",
                columns: table => new
            {
                UserId            = table.Column <int>(nullable: false),
                RoleId            = table.Column <int>(nullable: false),
                CreationTime      = table.Column <DateTimeOffset>(nullable: false),
                CreatorId         = table.Column <int>(nullable: true),
                InsertOrder       = table.Column <long>(nullable: false),
                ApplicationRoleId = table.Column <int>(nullable: true),
                ApplicationUserId = table.Column <int>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_AppUserRoles", x => new { x.UserId, x.RoleId });
                table.ForeignKey(
                    name: "FK_AppUserRoles_AppRoles_ApplicationRoleId",
                    column: x => x.ApplicationRoleId,
                    principalTable: "AppRoles",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserRoles_AppUsers_ApplicationUserId",
                    column: x => x.ApplicationUserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserRoles_AppUsers_CreatorId",
                    column: x => x.CreatorId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_AppUserRoles_AppRoles_RoleId",
                    column: x => x.RoleId,
                    principalTable: "AppRoles",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
                table.ForeignKey(
                    name: "FK_AppUserRoles_AppUsers_UserId",
                    column: x => x.UserId,
                    principalTable: "AppUsers",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateIndex(
                name: "IX_AppOrganizations_CreatorId",
                table: "AppOrganizations",
                column: "CreatorId");

            migrationBuilder.CreateIndex(
                name: "IX_AppOrganizations_LastModifierId",
                table: "AppOrganizations",
                column: "LastModifierId");

            migrationBuilder.CreateIndex(
                name: "IX_AppOrganizations_ParentId",
                table: "AppOrganizations",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRoleClaims_ApplicationRoleId",
                table: "AppRoleClaims",
                column: "ApplicationRoleId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRoleClaims_CreatorId",
                table: "AppRoleClaims",
                column: "CreatorId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRoleClaims_LastModifierId",
                table: "AppRoleClaims",
                column: "LastModifierId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRoleClaims_RoleId",
                table: "AppRoleClaims",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRoles_CreatorId",
                table: "AppRoles",
                column: "CreatorId");

            migrationBuilder.CreateIndex(
                name: "IX_AppRoles_LastModifierId",
                table: "AppRoles",
                column: "LastModifierId");

            migrationBuilder.CreateIndex(
                name: "RoleNameIndex",
                table: "AppRoles",
                column: "NormalizedName",
                unique: true,
                filter: "[NormalizedName] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_AppRoles_ParentId",
                table: "AppRoles",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserClaims_ApplicationUserId",
                table: "AppUserClaims",
                column: "ApplicationUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserClaims_CreatorId",
                table: "AppUserClaims",
                column: "CreatorId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserClaims_LastModifierId",
                table: "AppUserClaims",
                column: "LastModifierId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserClaims_UserId",
                table: "AppUserClaims",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserLogins_ApplicationUserId",
                table: "AppUserLogins",
                column: "ApplicationUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserLogins_CreatorId",
                table: "AppUserLogins",
                column: "CreatorId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserLogins_UserId",
                table: "AppUserLogins",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserOrganizations_ApplicationUserId",
                table: "AppUserOrganizations",
                column: "ApplicationUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserOrganizations_CreatorId",
                table: "AppUserOrganizations",
                column: "CreatorId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserOrganizations_OrganizationId",
                table: "AppUserOrganizations",
                column: "OrganizationId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserOrganizations_OrganizationId1",
                table: "AppUserOrganizations",
                column: "OrganizationId1");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserRoles_ApplicationRoleId",
                table: "AppUserRoles",
                column: "ApplicationRoleId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserRoles_ApplicationUserId",
                table: "AppUserRoles",
                column: "ApplicationUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserRoles_CreatorId",
                table: "AppUserRoles",
                column: "CreatorId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserRoles_RoleId",
                table: "AppUserRoles",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUsers_CreatorId",
                table: "AppUsers",
                column: "CreatorId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUsers_LastModifierId",
                table: "AppUsers",
                column: "LastModifierId");

            migrationBuilder.CreateIndex(
                name: "EmailIndex",
                table: "AppUsers",
                column: "NormalizedEmail");

            migrationBuilder.CreateIndex(
                name: "UserNameIndex",
                table: "AppUsers",
                column: "NormalizedUserName",
                unique: true,
                filter: "[NormalizedUserName] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserTokens_ApplicationUserId",
                table: "AppUserTokens",
                column: "ApplicationUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AppUserTokens_CreatorId",
                table: "AppUserTokens",
                column: "CreatorId");

            migrationBuilder.ApplyDatabaseDescription(this);
            migrationBuilder.CreateTreeEntityView(TargetModel.GetEntityTypes());
        }