using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace JobTrackerApi.Migrations { /// public partial class AddUserOperations : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { // This table is EF-owned. The migration branches explicitly because SQLite-scaffolded // TEXT/INTEGER types are not a safe MariaDB contract; do not duplicate it in the startup reconciler. if (ActiveProvider.Contains("MySql", StringComparison.OrdinalIgnoreCase)) { migrationBuilder.Sql(""" CREATE TABLE `UserOperations` ( `Id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL, `OwnerUserId` varchar(255) NOT NULL, `TaskType` varchar(64) NOT NULL, `IdempotencyKey` varchar(128) NOT NULL, `Status` varchar(32) NOT NULL, `Priority` int NOT NULL, `EntitlementDecision` varchar(32) NOT NULL, `PrivacyPolicy` varchar(32) NOT NULL, `SubjectType` varchar(64) NULL, `SubjectId` varchar(128) NULL, `Provider` varchar(128) NULL, `Model` varchar(128) NULL, `AttemptCount` int NOT NULL, `MaxAttempts` int NOT NULL, `CreatedAtUtc` datetime(6) NOT NULL, `AvailableAtUtc` datetime(6) NOT NULL, `StartedAtUtc` datetime(6) NULL, `CompletedAtUtc` datetime(6) NULL, `DeadlineAtUtc` datetime(6) NULL, `CancellationRequestedAtUtc` datetime(6) NULL, `LeaseToken` char(32) CHARACTER SET ascii COLLATE ascii_general_ci NULL, `LeaseExpiresAtUtc` datetime(6) NULL, `LastHeartbeatAtUtc` datetime(6) NULL, `ProgressStage` varchar(64) NULL, `ProgressPercent` int NULL, `FailureCategory` varchar(64) NULL, `FailureMessage` varchar(512) NULL, `ResultReference` varchar(256) NULL, CONSTRAINT `PK_UserOperations` PRIMARY KEY (`Id`) ) CHARACTER SET=utf8mb4; """); } else { migrationBuilder.CreateTable( name: "UserOperations", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), OwnerUserId = table.Column(type: "TEXT", maxLength: 255, nullable: false), TaskType = table.Column(type: "TEXT", maxLength: 64, nullable: false), IdempotencyKey = table.Column(type: "TEXT", maxLength: 128, nullable: false), Status = table.Column(type: "TEXT", maxLength: 32, nullable: false), Priority = table.Column(type: "INTEGER", nullable: false), EntitlementDecision = table.Column(type: "TEXT", maxLength: 32, nullable: false), PrivacyPolicy = table.Column(type: "TEXT", maxLength: 32, nullable: false), SubjectType = table.Column(type: "TEXT", maxLength: 64, nullable: true), SubjectId = table.Column(type: "TEXT", maxLength: 128, nullable: true), Provider = table.Column(type: "TEXT", maxLength: 128, nullable: true), Model = table.Column(type: "TEXT", maxLength: 128, nullable: true), AttemptCount = table.Column(type: "INTEGER", nullable: false), MaxAttempts = table.Column(type: "INTEGER", nullable: false), CreatedAtUtc = table.Column(type: "TEXT", nullable: false), AvailableAtUtc = table.Column(type: "TEXT", nullable: false), StartedAtUtc = table.Column(type: "TEXT", nullable: true), CompletedAtUtc = table.Column(type: "TEXT", nullable: true), DeadlineAtUtc = table.Column(type: "TEXT", nullable: true), CancellationRequestedAtUtc = table.Column(type: "TEXT", nullable: true), LeaseToken = table.Column(type: "TEXT", maxLength: 32, nullable: true), LeaseExpiresAtUtc = table.Column(type: "TEXT", nullable: true), LastHeartbeatAtUtc = table.Column(type: "TEXT", nullable: true), ProgressStage = table.Column(type: "TEXT", maxLength: 64, nullable: true), ProgressPercent = table.Column(type: "INTEGER", nullable: true), FailureCategory = table.Column(type: "TEXT", maxLength: 64, nullable: true), FailureMessage = table.Column(type: "TEXT", maxLength: 512, nullable: true), ResultReference = table.Column(type: "TEXT", maxLength: 256, nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserOperations", x => x.Id); }); } migrationBuilder.CreateIndex( name: "IX_UserOperations_OwnerUserId_TaskType_IdempotencyKey", table: "UserOperations", columns: new[] { "OwnerUserId", "TaskType", "IdempotencyKey" }, unique: true); migrationBuilder.CreateIndex( name: "IX_UserOperations_Status_AvailableAtUtc_Priority", table: "UserOperations", columns: new[] { "Status", "AvailableAtUtc", "Priority" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "UserOperations"); } } }