BEGIN TRANSACTION;
CREATE TABLE "UserOperations" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_UserOperations" PRIMARY KEY,
    "OwnerUserId" TEXT NOT NULL,
    "TaskType" TEXT NOT NULL,
    "IdempotencyKey" TEXT NOT NULL,
    "Status" TEXT NOT NULL,
    "Priority" INTEGER NOT NULL,
    "EntitlementDecision" TEXT NOT NULL,
    "PrivacyPolicy" TEXT NOT NULL,
    "SubjectType" TEXT NULL,
    "SubjectId" TEXT NULL,
    "Provider" TEXT NULL,
    "Model" TEXT NULL,
    "AttemptCount" INTEGER NOT NULL,
    "MaxAttempts" INTEGER NOT NULL,
    "CreatedAtUtc" TEXT NOT NULL,
    "AvailableAtUtc" TEXT NOT NULL,
    "StartedAtUtc" TEXT NULL,
    "CompletedAtUtc" TEXT NULL,
    "DeadlineAtUtc" TEXT NULL,
    "CancellationRequestedAtUtc" TEXT NULL,
    "LeaseToken" TEXT NULL,
    "LeaseExpiresAtUtc" TEXT NULL,
    "LastHeartbeatAtUtc" TEXT NULL,
    "ProgressStage" TEXT NULL,
    "ProgressPercent" INTEGER NULL,
    "FailureCategory" TEXT NULL,
    "FailureMessage" TEXT NULL,
    "ResultReference" TEXT NULL
);

CREATE UNIQUE INDEX "IX_UserOperations_OwnerUserId_TaskType_IdempotencyKey" ON "UserOperations" ("OwnerUserId", "TaskType", "IdempotencyKey");

CREATE INDEX "IX_UserOperations_Status_AvailableAtUtc_Priority" ON "UserOperations" ("Status", "AvailableAtUtc", "Priority");

INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260802224646_AddUserOperations', '9.0.14');

COMMIT;

