20260425221653_AddEmailLogQueue.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb
  5. {
  6. /// <inheritdoc />
  7. public partial class AddEmailLogQueue : Migration
  8. {
  9. /// <inheritdoc />
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.CreateTable(
  13. name: "EmailLog",
  14. columns: table => new
  15. {
  16. ID = table.Column<long>(type: "bigint", nullable: false, comment: "PK")
  17. .Annotation("SqlServer:Identity", "1, 1"),
  18. ToAddress = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false, comment: "수신자 이메일"),
  19. Subject = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false, comment: "제목"),
  20. MessageHtml = table.Column<string>(type: "nvarchar(max)", nullable: false, comment: "HTML 본문"),
  21. MessageText = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "텍스트 본문 (선택)"),
  22. Status = table.Column<byte>(type: "tinyint", nullable: false, defaultValue: (byte)0, comment: "상태 (0=Pending, 1=Processing, 2=Sent, 3=Failed)"),
  23. RetryCount = table.Column<int>(type: "int", nullable: false, defaultValue: 0, comment: "재시도 횟수"),
  24. MaxRetryCount = table.Column<int>(type: "int", nullable: false, defaultValue: 3, comment: "최대 재시도 횟수"),
  25. NextRetryAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()", comment: "다음 시도 시각 (UTC)"),
  26. LastError = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "마지막 오류 메시지"),
  27. Category = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true, comment: "카테고리 (auth.register, forum.post.notify 등)"),
  28. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()", comment: "등록 시각 (UTC)"),
  29. ProcessedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "처리 완료 시각 (UTC)"),
  30. FailedAt = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "실패 확정 시각 (UTC)")
  31. },
  32. constraints: table =>
  33. {
  34. table.PrimaryKey("PK_EmailLog", x => x.ID);
  35. },
  36. comment: "이메일 발송 큐");
  37. migrationBuilder.CreateIndex(
  38. name: "IX_EmailLog_CreatedAt",
  39. table: "EmailLog",
  40. column: "CreatedAt");
  41. migrationBuilder.CreateIndex(
  42. name: "IX_EmailLog_Status_NextRetryAt",
  43. table: "EmailLog",
  44. columns: new[] { "Status", "NextRetryAt" });
  45. }
  46. /// <inheritdoc />
  47. protected override void Down(MigrationBuilder migrationBuilder)
  48. {
  49. migrationBuilder.DropTable(
  50. name: "EmailLog");
  51. }
  52. }
  53. }