using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace MiaoJiZhang.Infrastructure.Persistence.Migrations { /// public partial class TransferAndAdminSecurity : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "Counterparty", table: "Transactions", type: "varchar(100)", maxLength: 100, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.AddColumn( name: "EvidenceFingerprint", table: "Transactions", type: "varchar(64)", maxLength: 64, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.AddColumn( name: "Provider", table: "Transactions", type: "varchar(24)", maxLength: 24, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.AddColumn( name: "ProviderTransactionId", table: "Transactions", type: "varchar(128)", maxLength: 128, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.AddColumn( name: "RecognitionConfidence", table: "Transactions", type: "varchar(24)", maxLength: 24, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.AddColumn( name: "RecognitionOccurrenceId", table: "Transactions", type: "varchar(64)", maxLength: 64, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.AddColumn( name: "TransferDirection", table: "Transactions", type: "int", nullable: true); migrationBuilder.CreateTable( name: "AdminAuditLogs", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), AdminUserId = table.Column(type: "bigint", nullable: true), Username = table.Column(type: "varchar(64)", maxLength: 64, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), Action = table.Column(type: "varchar(80)", maxLength: 80, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Resource = table.Column(type: "varchar(120)", maxLength: 120, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), HttpMethod = table.Column(type: "varchar(12)", maxLength: 12, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Path = table.Column(type: "varchar(300)", maxLength: 300, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), StatusCode = table.Column(type: "int", nullable: false), Success = table.Column(type: "tinyint(1)", nullable: false), Detail = table.Column(type: "varchar(1000)", maxLength: 1000, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), IpAddress = table.Column(type: "varchar(64)", maxLength: 64, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AdminAuditLogs", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "AdminUsers", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Username = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), PasswordHash = table.Column(type: "varchar(128)", maxLength: 128, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Role = table.Column(type: "varchar(24)", maxLength: 24, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), IsActive = table.Column(type: "tinyint(1)", nullable: false), MustChangePassword = table.Column(type: "tinyint(1)", nullable: false), AuthVersion = table.Column(type: "int", nullable: false), FailedLoginCount = table.Column(type: "int", nullable: false), LockedUntil = table.Column(type: "datetime(6)", nullable: true), LastLoginAt = table.Column(type: "datetime(6)", nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AdminUsers", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "AdminSessions", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), AdminUserId = table.Column(type: "bigint", nullable: false), TokenHash = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), CsrfTokenHash = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), AuthVersion = table.Column(type: "int", nullable: false), ExpiresAt = table.Column(type: "datetime(6)", nullable: false), AbsoluteExpiresAt = table.Column(type: "datetime(6)", nullable: false), RevokedAt = table.Column(type: "datetime(6)", nullable: true), LastSeenAt = table.Column(type: "datetime(6)", nullable: false), IpAddress = table.Column(type: "varchar(64)", maxLength: 64, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), UserAgent = table.Column(type: "varchar(300)", maxLength: 300, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AdminSessions", x => x.Id); table.ForeignKey( name: "FK_AdminSessions_AdminUsers_AdminUserId", column: x => x.AdminUserId, principalTable: "AdminUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_Transactions_UserId_Provider_ProviderTransactionId", table: "Transactions", columns: new[] { "UserId", "Provider", "ProviderTransactionId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Transactions_UserId_RecognitionOccurrenceId", table: "Transactions", columns: new[] { "UserId", "RecognitionOccurrenceId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_AdminAuditLogs_AdminUserId_CreatedAt", table: "AdminAuditLogs", columns: new[] { "AdminUserId", "CreatedAt" }); migrationBuilder.CreateIndex( name: "IX_AdminAuditLogs_CreatedAt", table: "AdminAuditLogs", column: "CreatedAt"); migrationBuilder.CreateIndex( name: "IX_AdminSessions_AdminUserId_RevokedAt_ExpiresAt", table: "AdminSessions", columns: new[] { "AdminUserId", "RevokedAt", "ExpiresAt" }); migrationBuilder.CreateIndex( name: "IX_AdminSessions_TokenHash", table: "AdminSessions", column: "TokenHash", unique: true); migrationBuilder.CreateIndex( name: "IX_AdminUsers_IsActive_Role", table: "AdminUsers", columns: new[] { "IsActive", "Role" }); migrationBuilder.CreateIndex( name: "IX_AdminUsers_Username", table: "AdminUsers", column: "Username", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AdminAuditLogs"); migrationBuilder.DropTable( name: "AdminSessions"); migrationBuilder.DropTable( name: "AdminUsers"); migrationBuilder.DropIndex( name: "IX_Transactions_UserId_Provider_ProviderTransactionId", table: "Transactions"); migrationBuilder.DropIndex( name: "IX_Transactions_UserId_RecognitionOccurrenceId", table: "Transactions"); migrationBuilder.DropColumn( name: "Counterparty", table: "Transactions"); migrationBuilder.DropColumn( name: "EvidenceFingerprint", table: "Transactions"); migrationBuilder.DropColumn( name: "Provider", table: "Transactions"); migrationBuilder.DropColumn( name: "ProviderTransactionId", table: "Transactions"); migrationBuilder.DropColumn( name: "RecognitionConfidence", table: "Transactions"); migrationBuilder.DropColumn( name: "RecognitionOccurrenceId", table: "Transactions"); migrationBuilder.DropColumn( name: "TransferDirection", table: "Transactions"); } } }