49 lines
2.0 KiB
C#
49 lines
2.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Tiku.Domain.Learning;
|
|
|
|
namespace Tiku.Infrastructure.Persistence.Configurations;
|
|
|
|
internal sealed class LearningOutboxMessageConfiguration : IEntityTypeConfiguration<LearningOutboxMessage>
|
|
{
|
|
public void Configure(EntityTypeBuilder<LearningOutboxMessage> builder)
|
|
{
|
|
builder.ConfigureTenantEntity("learning_outbox_messages");
|
|
builder.Property(entity => entity.EventType).HasMaxLength(100);
|
|
builder.Property(entity => entity.Payload).IsJson("{}");
|
|
builder.Property(entity => entity.OccurredAt).HasDefaultValueSql("now()");
|
|
builder.Property(entity => entity.AvailableAt).HasDefaultValueSql("now()");
|
|
builder.Property(entity => entity.LockedBy).HasMaxLength(200);
|
|
builder.Property(entity => entity.LastError).HasMaxLength(2000);
|
|
builder.HasIndex(entity => new { entity.TenantId, entity.EventType, entity.AggregateId }).IsUnique();
|
|
builder.HasIndex(entity => new
|
|
{
|
|
entity.AvailableAt,
|
|
entity.LockExpiresAt,
|
|
entity.OccurredAt,
|
|
entity.Id
|
|
})
|
|
.HasDatabaseName("ix_learning_outbox_pending")
|
|
.HasFilter("processed_at IS NULL AND dead_lettered_at IS NULL");
|
|
builder.ToTable(table => table.HasCheckConstraint(
|
|
"ck_learning_outbox_messages_attempt_count",
|
|
"attempt_count >= 0"));
|
|
}
|
|
}
|
|
|
|
internal sealed class LearningProjectionReceiptConfiguration : IEntityTypeConfiguration<LearningProjectionReceipt>
|
|
{
|
|
public void Configure(EntityTypeBuilder<LearningProjectionReceipt> builder)
|
|
{
|
|
builder.ConfigureTenantEntity("learning_projection_receipts");
|
|
builder.Property(entity => entity.ProjectionName).HasMaxLength(100);
|
|
builder.Property(entity => entity.ProcessedAt).HasDefaultValueSql("now()");
|
|
builder.HasIndex(entity => new
|
|
{
|
|
entity.TenantId,
|
|
entity.OutboxMessageId,
|
|
entity.ProjectionName
|
|
}).IsUnique();
|
|
}
|
|
}
|