Files
jobtrackingapp/JobTrackerApi/Migrations/20260809195014_AddEmailSendAttempts.cs
T
cesnimda 653f011be2
CI and Deploy / test (pull_request) Failing after 1m21s
CI and Deploy / deploy (pull_request) Has been skipped
feat(email): add durable send ledger
Tracks only idempotency and delivery metadata; recipient, subject, and body are excluded. No provider send path is enabled.
2026-08-09 23:32:27 +02:00

92 lines
4.3 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace JobTrackerApi.Migrations
{
/// <inheritdoc />
public partial class AddEmailSendAttempts : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
if (ActiveProvider.Contains("MySql", StringComparison.OrdinalIgnoreCase))
{
migrationBuilder.Sql("""
CREATE TABLE `EmailSendAttempts` (
`Id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
`OwnerUserId` varchar(255) NOT NULL,
`JobApplicationId` int NOT NULL,
`Provider` varchar(32) NOT NULL,
`ClientRequestId` varchar(128) NOT NULL,
`PayloadHash` char(64) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
`Status` varchar(32) NOT NULL,
`ProviderMessageId` varchar(256) NULL,
`FailureCategory` varchar(64) NULL,
`CreatedAtUtc` datetime(6) NOT NULL,
`StartedAtUtc` datetime(6) NULL,
`CompletedAtUtc` datetime(6) NULL,
CONSTRAINT `PK_EmailSendAttempts` PRIMARY KEY (`Id`),
CONSTRAINT `FK_EmailSendAttempts_JobApplications_JobApplicationId`
FOREIGN KEY (`JobApplicationId`) REFERENCES `JobApplications` (`Id`) ON DELETE CASCADE
) CHARACTER SET=utf8mb4;
""");
}
else
{
migrationBuilder.CreateTable(
name: "EmailSendAttempts",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
OwnerUserId = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
JobApplicationId = table.Column<int>(type: "INTEGER", nullable: false),
Provider = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
ClientRequestId = table.Column<string>(type: "TEXT", maxLength: 128, nullable: false),
PayloadHash = table.Column<string>(type: "TEXT", maxLength: 64, nullable: false),
Status = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
ProviderMessageId = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
FailureCategory = table.Column<string>(type: "TEXT", maxLength: 64, nullable: true),
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
StartedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
CompletedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_EmailSendAttempts", x => x.Id);
table.ForeignKey(
name: "FK_EmailSendAttempts_JobApplications_JobApplicationId",
column: x => x.JobApplicationId,
principalTable: "JobApplications",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
}
migrationBuilder.CreateIndex(
name: "IX_EmailSendAttempts_JobApplicationId",
table: "EmailSendAttempts",
column: "JobApplicationId");
migrationBuilder.CreateIndex(
name: "IX_EmailSendAttempts_OwnerUserId_ClientRequestId",
table: "EmailSendAttempts",
columns: new[] { "OwnerUserId", "ClientRequestId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_EmailSendAttempts_OwnerUserId_CreatedAtUtc",
table: "EmailSendAttempts",
columns: new[] { "OwnerUserId", "CreatedAtUtc" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EmailSendAttempts");
}
}
}