using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations.AppDb
{
///
public partial class AddEmailLogQueue : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "EmailLog",
columns: table => new
{
ID = table.Column(type: "bigint", nullable: false, comment: "PK")
.Annotation("SqlServer:Identity", "1, 1"),
ToAddress = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false, comment: "수신자 이메일"),
Subject = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false, comment: "제목"),
MessageHtml = table.Column(type: "nvarchar(max)", nullable: false, comment: "HTML 본문"),
MessageText = table.Column(type: "nvarchar(max)", nullable: true, comment: "텍스트 본문 (선택)"),
Status = table.Column(type: "tinyint", nullable: false, defaultValue: (byte)0, comment: "상태 (0=Pending, 1=Processing, 2=Sent, 3=Failed)"),
RetryCount = table.Column(type: "int", nullable: false, defaultValue: 0, comment: "재시도 횟수"),
MaxRetryCount = table.Column(type: "int", nullable: false, defaultValue: 3, comment: "최대 재시도 횟수"),
NextRetryAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()", comment: "다음 시도 시각 (UTC)"),
LastError = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "마지막 오류 메시지"),
Category = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true, comment: "카테고리 (auth.register, forum.post.notify 등)"),
CreatedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()", comment: "등록 시각 (UTC)"),
ProcessedAt = table.Column(type: "datetime2", nullable: true, comment: "처리 완료 시각 (UTC)"),
FailedAt = table.Column(type: "datetime2", nullable: true, comment: "실패 확정 시각 (UTC)")
},
constraints: table =>
{
table.PrimaryKey("PK_EmailLog", x => x.ID);
},
comment: "이메일 발송 큐");
migrationBuilder.CreateIndex(
name: "IX_EmailLog_CreatedAt",
table: "EmailLog",
column: "CreatedAt");
migrationBuilder.CreateIndex(
name: "IX_EmailLog_Status_NextRetryAt",
table: "EmailLog",
columns: new[] { "Status", "NextRetryAt" });
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EmailLog");
}
}
}