using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using ScadaLink.Commons.Entities.Notifications; namespace ScadaLink.ConfigurationDatabase.Configurations; /// /// EF Core mapping for the central notification outbox entity. /// and are intentionally left unconstrained /// (nullable nvarchar(max)) as they carry variable-length JSON / target snapshots. /// public class NotificationOutboxConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasKey(n => n.NotificationId); builder.Property(n => n.NotificationId).HasMaxLength(64); builder.Property(n => n.Type) .HasConversion() .HasMaxLength(32) .IsRequired(); builder.Property(n => n.Status) .HasConversion() .HasMaxLength(32) .IsRequired(); builder.Property(n => n.ListName) .HasMaxLength(200) .IsRequired(); builder.Property(n => n.Subject) .HasMaxLength(1000) .IsRequired(); builder.Property(n => n.Body).IsRequired(); builder.Property(n => n.LastError).HasMaxLength(4000); builder.Property(n => n.SourceSiteId) .HasMaxLength(100) .IsRequired(); builder.Property(n => n.SourceInstanceId).HasMaxLength(200); builder.Property(n => n.SourceScript).HasMaxLength(200); // OriginExecutionId (Audit Log #23): nullable uniqueidentifier carried from the // site so the dispatcher can echo it onto NotifyDeliver audit rows. No index — // it is never a query predicate on this table, only copied onto audit events. // OriginParentExecutionId (Audit Log #23): nullable uniqueidentifier carried from // the site — the routed run's parent ExecutionId — so the dispatcher can echo it // onto NotifyDeliver audit rows. No index — same rationale as OriginExecutionId. builder.HasIndex(n => new { n.Status, n.NextAttemptAt }); builder.HasIndex(n => new { n.SourceSiteId, n.CreatedAt }); } }