using System; using Microsoft.EntityFrameworkCore.Migrations; using MySql.EntityFrameworkCore.Metadata; #nullable disable namespace SlpModularCms.Core.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "AvailabilityState", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), Status = table.Column(type: "int", nullable: false), Message = table.Column(type: "longtext", nullable: true), LastUpdatedAt = table.Column(type: "datetime", nullable: false), UpdatedBy = table.Column(type: "longtext", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AvailabilityState", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "DataProtectionKeys", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), FriendlyName = table.Column(type: "longtext", nullable: true), Xml = table.Column(type: "longtext", nullable: true) }, constraints: table => { table.PrimaryKey("PK_DataProtectionKeys", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Invitations", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), Email = table.Column(type: "varchar(256)", maxLength: 256, nullable: false), Role = table.Column(type: "longtext", nullable: false), Token = table.Column(type: "varchar(256)", maxLength: 256, nullable: false), ExpiryDate = table.Column(type: "datetime", nullable: false), IsAccepted = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Invitations", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Roles", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), Name = table.Column(type: "varchar(256)", maxLength: 256, nullable: true), NormalizedName = table.Column(type: "varchar(256)", maxLength: 256, nullable: true), ConcurrencyStamp = table.Column(type: "longtext", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Roles", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), DisplayName = table.Column(type: "longtext", nullable: true), UserName = table.Column(type: "varchar(256)", maxLength: 256, nullable: true), NormalizedUserName = table.Column(type: "varchar(256)", maxLength: 256, nullable: true), Email = table.Column(type: "varchar(256)", maxLength: 256, nullable: true), NormalizedEmail = table.Column(type: "varchar(256)", maxLength: 256, nullable: true), EmailConfirmed = table.Column(type: "tinyint(1)", nullable: false), PasswordHash = table.Column(type: "longtext", nullable: true), SecurityStamp = table.Column(type: "longtext", nullable: true), ConcurrencyStamp = table.Column(type: "longtext", nullable: true), PhoneNumber = table.Column(type: "longtext", nullable: true), PhoneNumberConfirmed = table.Column(type: "tinyint(1)", nullable: false), TwoFactorEnabled = table.Column(type: "tinyint(1)", nullable: false), LockoutEnd = table.Column(type: "datetime", nullable: true), LockoutEnabled = table.Column(type: "tinyint(1)", nullable: false), AccessFailedCount = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "RoleClaims", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), RoleId = table.Column(type: "char(36)", nullable: false), ClaimType = table.Column(type: "longtext", nullable: true), ClaimValue = table.Column(type: "longtext", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RoleClaims", x => x.Id); table.ForeignKey( name: "FK_RoleClaims_Roles_RoleId", column: x => x.RoleId, principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "ModulePermissions", columns: table => new { UserId = table.Column(type: "char(36)", nullable: false), ModuleName = table.Column(type: "varchar(128)", maxLength: 128, nullable: false), Permission = table.Column(type: "varchar(128)", maxLength: 128, nullable: false) }, constraints: table => { table.PrimaryKey("PK_ModulePermissions", x => new { x.UserId, x.ModuleName, x.Permission }); table.ForeignKey( name: "FK_ModulePermissions_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "RefreshTokens", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), Token = table.Column(type: "varchar(256)", maxLength: 256, nullable: false), UserId = table.Column(type: "char(36)", nullable: false), ExpiryDate = table.Column(type: "datetime", nullable: false), IsUsed = table.Column(type: "tinyint(1)", nullable: false), IsRevoked = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime", nullable: false), CreatedByIp = table.Column(type: "longtext", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RefreshTokens", x => x.Id); table.ForeignKey( name: "FK_RefreshTokens_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "UserClaims", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), UserId = table.Column(type: "char(36)", nullable: false), ClaimType = table.Column(type: "longtext", nullable: true), ClaimValue = table.Column(type: "longtext", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserClaims", x => x.Id); table.ForeignKey( name: "FK_UserClaims_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "UserLogins", columns: table => new { LoginProvider = table.Column(type: "varchar(255)", nullable: false), ProviderKey = table.Column(type: "varchar(255)", nullable: false), ProviderDisplayName = table.Column(type: "longtext", nullable: true), UserId = table.Column(type: "char(36)", 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); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "UserRoles", columns: table => new { UserId = table.Column(type: "char(36)", nullable: false), RoleId = table.Column(type: "char(36)", 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); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "UserTokens", columns: table => new { UserId = table.Column(type: "char(36)", nullable: false), LoginProvider = table.Column(type: "varchar(255)", nullable: false), Name = table.Column(type: "varchar(255)", nullable: false), Value = table.Column(type: "longtext", 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); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_Invitations_Token", table: "Invitations", column: "Token", unique: true); migrationBuilder.CreateIndex( name: "IX_RefreshTokens_Token", table: "RefreshTokens", column: "Token", unique: true); migrationBuilder.CreateIndex( name: "IX_RefreshTokens_UserId", table: "RefreshTokens", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_RoleClaims_RoleId", table: "RoleClaims", column: "RoleId"); migrationBuilder.CreateIndex( name: "RoleNameIndex", table: "Roles", column: "NormalizedName", unique: true); 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); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AvailabilityState"); migrationBuilder.DropTable( name: "DataProtectionKeys"); migrationBuilder.DropTable( name: "Invitations"); migrationBuilder.DropTable( name: "ModulePermissions"); migrationBuilder.DropTable( name: "RefreshTokens"); migrationBuilder.DropTable( name: "RoleClaims"); migrationBuilder.DropTable( name: "UserClaims"); migrationBuilder.DropTable( name: "UserLogins"); migrationBuilder.DropTable( name: "UserRoles"); migrationBuilder.DropTable( name: "UserTokens"); migrationBuilder.DropTable( name: "Roles"); migrationBuilder.DropTable( name: "Users"); } } }