using System; using Microsoft.EntityFrameworkCore.Migrations; namespace UserManagement.Domain.Migrations { public partial class Inital : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "AppSettings", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: true), Key = table.Column(type: "nvarchar(max)", nullable: true), Value = table.Column(type: "nvarchar(max)", nullable: true), CreatedDate = table.Column(type: "datetime2", nullable: false), CreatedBy = table.Column(type: "uniqueidentifier", nullable: false), ModifiedDate = table.Column(type: "datetime2", nullable: false, defaultValueSql: "getdate()"), ModifiedBy = table.Column(type: "uniqueidentifier", nullable: false), DeletedDate = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "uniqueidentifier", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AppSettings", x => x.Id); }); migrationBuilder.CreateTable( name: "EmailTemplates", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: true), Subject = table.Column(type: "nvarchar(max)", nullable: true), Body = table.Column(type: "nvarchar(max)", nullable: true), CreatedDate = table.Column(type: "datetime2", nullable: false), CreatedBy = table.Column(type: "uniqueidentifier", nullable: false), ModifiedDate = table.Column(type: "datetime2", nullable: false), ModifiedBy = table.Column(type: "uniqueidentifier", nullable: false), DeletedDate = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "uniqueidentifier", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_EmailTemplates", x => x.Id); }); migrationBuilder.CreateTable( name: "LoginAudits", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), UserName = table.Column(type: "nvarchar(max)", nullable: true), LoginTime = table.Column(type: "datetime2", nullable: false), RemoteIP = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true), Status = table.Column(type: "nvarchar(max)", nullable: true), Provider = table.Column(type: "nvarchar(max)", nullable: true), Latitude = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true), Longitude = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true) }, constraints: table => { table.PrimaryKey("PK_LoginAudits", x => x.Id); }); migrationBuilder.CreateTable( name: "NLog", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), MachineName = table.Column(type: "nvarchar(max)", nullable: true), Logged = table.Column(type: "datetime2", nullable: false), Level = table.Column(type: "nvarchar(max)", nullable: true), Message = table.Column(type: "nvarchar(max)", nullable: true), Logger = table.Column(type: "nvarchar(max)", nullable: true), Properties = table.Column(type: "nvarchar(max)", nullable: true), Callsite = table.Column(type: "nvarchar(max)", nullable: true), Exception = table.Column(type: "nvarchar(max)", nullable: true), Source = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true) }, constraints: table => { table.PrimaryKey("PK_NLog", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), FirstName = table.Column(type: "nvarchar(max)", nullable: true), LastName = table.Column(type: "nvarchar(max)", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), IsActive = table.Column(type: "bit", nullable: false), ProfilePhoto = table.Column(type: "nvarchar(max)", nullable: true), Provider = table.Column(type: "nvarchar(max)", nullable: true), Address = table.Column(type: "nvarchar(max)", nullable: true), CreatedDate = table.Column(type: "datetime2", nullable: false), CreatedBy = table.Column(type: "uniqueidentifier", nullable: true), ModifiedDate = table.Column(type: "datetime2", nullable: false, defaultValueSql: "getdate()"), ModifiedBy = table.Column(type: "uniqueidentifier", nullable: true), DeletedDate = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "uniqueidentifier", nullable: true), UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), EmailConfirmed = table.Column(type: "bit", nullable: false), PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), TwoFactorEnabled = table.Column(type: "bit", nullable: false), LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), LockoutEnabled = table.Column(type: "bit", nullable: false), AccessFailedCount = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Actions", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: true), CreatedDate = table.Column(type: "datetime2", nullable: false), CreatedBy = table.Column(type: "uniqueidentifier", nullable: false), ModifiedDate = table.Column(type: "datetime2", nullable: false, defaultValueSql: "getdate()"), ModifiedBy = table.Column(type: "uniqueidentifier", nullable: false), DeletedDate = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "uniqueidentifier", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Actions", x => x.Id); table.ForeignKey( name: "FK_Actions_Users_CreatedBy", column: x => x.CreatedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_Actions_Users_DeletedBy", column: x => x.DeletedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_Actions_Users_ModifiedBy", column: x => x.ModifiedBy, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "EmailSMTPSettings", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Host = table.Column(type: "nvarchar(max)", nullable: false), UserName = table.Column(type: "nvarchar(max)", nullable: false), Password = table.Column(type: "nvarchar(max)", nullable: false), IsEnableSSL = table.Column(type: "bit", nullable: false), Port = table.Column(type: "int", nullable: false), IsDefault = table.Column(type: "bit", nullable: false), CreatedDate = table.Column(type: "datetime2", nullable: false), CreatedBy = table.Column(type: "uniqueidentifier", nullable: false), ModifiedDate = table.Column(type: "datetime2", nullable: false), ModifiedBy = table.Column(type: "uniqueidentifier", nullable: false), DeletedDate = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "uniqueidentifier", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_EmailSMTPSettings", x => x.Id); table.ForeignKey( name: "FK_EmailSMTPSettings_Users_CreatedBy", column: x => x.CreatedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_EmailSMTPSettings_Users_DeletedBy", column: x => x.DeletedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_EmailSMTPSettings_Users_ModifiedBy", column: x => x.ModifiedBy, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Pages", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: true), Url = table.Column(type: "nvarchar(max)", nullable: true), CreatedDate = table.Column(type: "datetime2", nullable: false), CreatedBy = table.Column(type: "uniqueidentifier", nullable: false), ModifiedDate = table.Column(type: "datetime2", nullable: false, defaultValueSql: "getdate()"), ModifiedBy = table.Column(type: "uniqueidentifier", nullable: false), DeletedDate = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "uniqueidentifier", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Pages", x => x.Id); table.ForeignKey( name: "FK_Pages_Users_CreatedBy", column: x => x.CreatedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_Pages_Users_DeletedBy", column: x => x.DeletedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_Pages_Users_ModifiedBy", column: x => x.ModifiedBy, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Roles", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), IsDeleted = table.Column(type: "bit", nullable: false), CreatedDate = table.Column(type: "datetime2", nullable: false), CreatedBy = table.Column(type: "uniqueidentifier", nullable: true), ModifiedDate = table.Column(type: "datetime2", nullable: false, defaultValueSql: "getdate()"), ModifiedBy = table.Column(type: "uniqueidentifier", nullable: false), DeletedDate = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "uniqueidentifier", nullable: true), Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Roles", x => x.Id); table.ForeignKey( name: "FK_Roles_Users_CreatedBy", column: x => x.CreatedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_Roles_Users_DeletedBy", column: x => x.DeletedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_Roles_Users_ModifiedBy", column: x => x.ModifiedBy, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "UserAllowedIPs", columns: table => new { UserId = table.Column(type: "uniqueidentifier", nullable: false), IPAddress = table.Column(type: "nvarchar(450)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserAllowedIPs", x => new { x.UserId, x.IPAddress }); table.ForeignKey( name: "FK_UserAllowedIPs_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserLogins", columns: table => new { LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), UserId = table.Column(type: "uniqueidentifier", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserLogins", x => new { x.LoginProvider, x.ProviderKey }); table.ForeignKey( name: "FK_UserLogins_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserTokens", columns: table => new { UserId = table.Column(type: "uniqueidentifier", nullable: false), LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), Name = table.Column(type: "nvarchar(450)", nullable: false), Value = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); table.ForeignKey( name: "FK_UserTokens_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "PageActions", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), ActionId = table.Column(type: "uniqueidentifier", nullable: false), PageId = table.Column(type: "uniqueidentifier", nullable: false), CreatedDate = table.Column(type: "datetime2", nullable: false), CreatedBy = table.Column(type: "uniqueidentifier", nullable: false), ModifiedDate = table.Column(type: "datetime2", nullable: false, defaultValueSql: "getdate()"), ModifiedBy = table.Column(type: "uniqueidentifier", nullable: false), DeletedDate = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "uniqueidentifier", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PageActions", x => x.Id); table.ForeignKey( name: "FK_PageActions_Actions_ActionId", column: x => x.ActionId, principalTable: "Actions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PageActions_Pages_PageId", column: x => x.PageId, principalTable: "Pages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PageActions_Users_CreatedBy", column: x => x.CreatedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_PageActions_Users_DeletedBy", column: x => x.DeletedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_PageActions_Users_ModifiedBy", column: x => x.ModifiedBy, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "UserClaims", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ActionId = table.Column(type: "uniqueidentifier", nullable: false), PageId = table.Column(type: "uniqueidentifier", nullable: false), UserId = table.Column(type: "uniqueidentifier", nullable: false), ClaimType = table.Column(type: "nvarchar(max)", nullable: true), ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserClaims", x => x.Id); table.ForeignKey( name: "FK_UserClaims_Actions_ActionId", column: x => x.ActionId, principalTable: "Actions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserClaims_Pages_PageId", column: x => x.PageId, principalTable: "Pages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserClaims_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "RoleClaims", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ActionId = table.Column(type: "uniqueidentifier", nullable: false), PageId = table.Column(type: "uniqueidentifier", nullable: false), RoleId = table.Column(type: "uniqueidentifier", nullable: false), ClaimType = table.Column(type: "nvarchar(max)", nullable: true), ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RoleClaims", x => x.Id); table.ForeignKey( name: "FK_RoleClaims_Actions_ActionId", column: x => x.ActionId, principalTable: "Actions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_RoleClaims_Pages_PageId", column: x => x.PageId, principalTable: "Pages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_RoleClaims_Roles_RoleId", column: x => x.RoleId, principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserRoles", columns: table => new { UserId = table.Column(type: "uniqueidentifier", nullable: false), RoleId = table.Column(type: "uniqueidentifier", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId }); table.ForeignKey( name: "FK_UserRoles_Roles_RoleId", column: x => x.RoleId, principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserRoles_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Actions_CreatedBy", table: "Actions", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Actions_DeletedBy", table: "Actions", column: "DeletedBy"); migrationBuilder.CreateIndex( name: "IX_Actions_ModifiedBy", table: "Actions", column: "ModifiedBy"); migrationBuilder.CreateIndex( name: "IX_EmailSMTPSettings_CreatedBy", table: "EmailSMTPSettings", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_EmailSMTPSettings_DeletedBy", table: "EmailSMTPSettings", column: "DeletedBy"); migrationBuilder.CreateIndex( name: "IX_EmailSMTPSettings_ModifiedBy", table: "EmailSMTPSettings", column: "ModifiedBy"); migrationBuilder.CreateIndex( name: "IX_PageActions_ActionId", table: "PageActions", column: "ActionId"); migrationBuilder.CreateIndex( name: "IX_PageActions_CreatedBy", table: "PageActions", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_PageActions_DeletedBy", table: "PageActions", column: "DeletedBy"); migrationBuilder.CreateIndex( name: "IX_PageActions_ModifiedBy", table: "PageActions", column: "ModifiedBy"); migrationBuilder.CreateIndex( name: "IX_PageActions_PageId", table: "PageActions", column: "PageId"); migrationBuilder.CreateIndex( name: "IX_Pages_CreatedBy", table: "Pages", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Pages_DeletedBy", table: "Pages", column: "DeletedBy"); migrationBuilder.CreateIndex( name: "IX_Pages_ModifiedBy", table: "Pages", column: "ModifiedBy"); migrationBuilder.CreateIndex( name: "IX_RoleClaims_ActionId", table: "RoleClaims", column: "ActionId"); migrationBuilder.CreateIndex( name: "IX_RoleClaims_PageId", table: "RoleClaims", column: "PageId"); migrationBuilder.CreateIndex( name: "IX_RoleClaims_RoleId", table: "RoleClaims", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_Roles_CreatedBy", table: "Roles", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_Roles_DeletedBy", table: "Roles", column: "DeletedBy"); migrationBuilder.CreateIndex( name: "IX_Roles_ModifiedBy", table: "Roles", column: "ModifiedBy"); migrationBuilder.CreateIndex( name: "RoleNameIndex", table: "Roles", column: "NormalizedName", unique: true, filter: "[NormalizedName] IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_UserClaims_ActionId", table: "UserClaims", column: "ActionId"); migrationBuilder.CreateIndex( name: "IX_UserClaims_PageId", table: "UserClaims", column: "PageId"); migrationBuilder.CreateIndex( name: "IX_UserClaims_UserId", table: "UserClaims", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_UserLogins_UserId", table: "UserLogins", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_UserRoles_RoleId", table: "UserRoles", column: "RoleId"); migrationBuilder.CreateIndex( name: "EmailIndex", table: "Users", column: "NormalizedEmail"); migrationBuilder.CreateIndex( name: "UserNameIndex", table: "Users", column: "NormalizedUserName", unique: true, filter: "[NormalizedUserName] IS NOT NULL"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AppSettings"); migrationBuilder.DropTable( name: "EmailSMTPSettings"); migrationBuilder.DropTable( name: "EmailTemplates"); migrationBuilder.DropTable( name: "LoginAudits"); migrationBuilder.DropTable( name: "NLog"); migrationBuilder.DropTable( name: "PageActions"); migrationBuilder.DropTable( name: "RoleClaims"); migrationBuilder.DropTable( name: "UserAllowedIPs"); migrationBuilder.DropTable( name: "UserClaims"); migrationBuilder.DropTable( name: "UserLogins"); migrationBuilder.DropTable( name: "UserRoles"); migrationBuilder.DropTable( name: "UserTokens"); migrationBuilder.DropTable( name: "Actions"); migrationBuilder.DropTable( name: "Pages"); migrationBuilder.DropTable( name: "Roles"); migrationBuilder.DropTable( name: "Users"); } } }