51 lines
2.9 KiB
C#
51 lines
2.9 KiB
C#
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<long>(type: "INTEGER", nullable: false).Annotation("Sqlite:Autoincrement", true),
|
|
OperationId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
OwnerUserId = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
|
AtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
Kind = table.Column<string>(type: "TEXT", maxLength: 40, nullable: false),
|
|
Status = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
|
|
Stage = table.Column<string>(type: "TEXT", maxLength: 64, nullable: true),
|
|
Attempt = table.Column<int>(type: "INTEGER", nullable: false),
|
|
FailureCode = table.Column<string>(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");
|
|
}
|