EmailLogConfiguration.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using Domain.Entities.Common;
  2. using Domain.Entities.Common.ValueObject;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  5. namespace Infrastructure.Persistence.Configurations.Common;
  6. public sealed class EmailLogConfiguration : IEntityTypeConfiguration<EmailLog>
  7. {
  8. public void Configure(EntityTypeBuilder<EmailLog> builder)
  9. {
  10. builder.ToTable(nameof(EmailLog), x => x.HasComment("이메일 발송 큐"));
  11. builder.HasKey(x => x.ID);
  12. builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
  13. builder.Property(x => x.ToAddress).IsRequired().HasMaxLength(256).HasComment("수신자 이메일");
  14. builder.Property(x => x.Subject).IsRequired().HasMaxLength(500).HasComment("제목");
  15. builder.Property(x => x.MessageHtml).IsRequired().HasComment("HTML 본문");
  16. builder.Property(x => x.MessageText).HasComment("텍스트 본문 (선택)");
  17. builder.Property(x => x.Status).IsRequired().HasDefaultValue(MailStatus.Pending).HasComment("상태 (0=Pending, 1=Processing, 2=Sent, 3=Failed)");
  18. builder.Property(x => x.RetryCount).IsRequired().HasDefaultValue(0).HasComment("재시도 횟수");
  19. builder.Property(x => x.MaxRetryCount).IsRequired().HasDefaultValue(3).HasComment("최대 재시도 횟수");
  20. builder.Property(x => x.NextRetryAt).IsRequired().HasDefaultValueSql("GETUTCDATE()").HasComment("다음 시도 시각 (UTC)");
  21. builder.Property(x => x.LastError).HasMaxLength(500).HasComment("마지막 오류 메시지");
  22. builder.Property(x => x.Category).HasMaxLength(50).HasComment("카테고리 (auth.register, forum.post.notify 등)");
  23. builder.Property(x => x.CreatedAt).IsRequired().HasDefaultValueSql("GETUTCDATE()").HasComment("등록 시각 (UTC)");
  24. builder.Property(x => x.ProcessedAt).HasComment("처리 완료 시각 (UTC)");
  25. builder.Property(x => x.FailedAt).HasComment("실패 확정 시각 (UTC)");
  26. builder.HasIndex(x => new { x.Status, x.NextRetryAt }).HasDatabaseName("IX_EmailLog_Status_NextRetryAt");
  27. builder.HasIndex(x => x.CreatedAt).HasDatabaseName("IX_EmailLog_CreatedAt");
  28. }
  29. }