using JobTrackerApi.Data; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace JobTrackerApi.Migrations; [DbContext(typeof(JobTrackerContext))] [Migration("20261028090000_AddUserOperationEvents")] public sealed class AddUserOperationEvents : Migration { protected override void Up(MigrationBuilder migrationBuilder) { if (ActiveProvider?.Contains("MySql", StringComparison.OrdinalIgnoreCase) == true) migrationBuilder.Sql(""" CREATE TABLE `UserOperationEvents` ( `Id` bigint NOT NULL AUTO_INCREMENT, `OperationId` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL, `OwnerUserId` varchar(255) NOT NULL, `AtUtc` datetime(6) NOT NULL, `Kind` varchar(40) NOT NULL, `Status` varchar(32) NOT NULL, `Stage` varchar(64) NULL, `Attempt` int NOT NULL, `FailureCode` varchar(64) NULL, CONSTRAINT `PK_UserOperationEvents` PRIMARY KEY (`Id`), CONSTRAINT `FK_UserOperationEvents_UserOperations_OperationId` FOREIGN KEY (`OperationId`) REFERENCES `UserOperations` (`Id`) ON DELETE CASCADE ) CHARACTER SET=utf8mb4; """); else migrationBuilder.CreateTable("UserOperationEvents", table => new { Id = table.Column(type: "INTEGER", nullable: false).Annotation("Sqlite:Autoincrement", true), OperationId = table.Column(type: "TEXT", nullable: false), OwnerUserId = table.Column(type: "TEXT", maxLength: 255, nullable: false), AtUtc = table.Column(type: "TEXT", nullable: false), Kind = table.Column(type: "TEXT", maxLength: 40, nullable: false), Status = table.Column(type: "TEXT", maxLength: 32, nullable: false), Stage = table.Column(type: "TEXT", maxLength: 64, nullable: true), Attempt = table.Column(type: "INTEGER", nullable: false), FailureCode = table.Column(type: "TEXT", maxLength: 64, nullable: true), }, constraints: table => { table.PrimaryKey("PK_UserOperationEvents", x => x.Id); table.ForeignKey("FK_UserOperationEvents_UserOperations_OperationId", x => x.OperationId, "UserOperations", "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex("IX_UserOperationEvents_OperationId_Id", "UserOperationEvents", new[] { "OperationId", "Id" }); migrationBuilder.CreateIndex("IX_UserOperationEvents_AtUtc", "UserOperationEvents", "AtUtc"); } protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable("UserOperationEvents"); }