feat(notification-outbox): add Notification EF configuration and DbSet

This commit is contained in:
Joseph Doherty
2026-05-19 00:55:58 -04:00
parent 87ac9b8a4d
commit 761595309b
3 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ScadaLink.Commons.Entities.Notifications;
namespace ScadaLink.ConfigurationDatabase.Configurations;
/// <summary>
/// EF Core mapping for the central notification outbox entity. <see cref="Notification.TypeData"/>
/// and <see cref="Notification.ResolvedTargets"/> are intentionally left unconstrained
/// (nullable nvarchar(max)) as they carry variable-length JSON / target snapshots.
/// </summary>
public class NotificationOutboxConfiguration : IEntityTypeConfiguration<Notification>
{
public void Configure(EntityTypeBuilder<Notification> builder)
{
builder.ToTable("Notifications");
builder.HasKey(n => n.NotificationId);
builder.Property(n => n.NotificationId).HasMaxLength(64);
builder.Property(n => n.Type).HasConversion<string>().HasMaxLength(32).IsRequired();
builder.Property(n => n.Status).HasConversion<string>().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);
builder.HasIndex(n => new { n.Status, n.NextAttemptAt });
builder.HasIndex(n => new { n.SourceSiteId, n.CreatedAt });
}
}

View File

@@ -69,6 +69,7 @@ public class ScadaLinkDbContext : DbContext, IDataProtectionKeyContext
public DbSet<NotificationList> NotificationLists => Set<NotificationList>();
public DbSet<NotificationRecipient> NotificationRecipients => Set<NotificationRecipient>();
public DbSet<SmtpConfiguration> SmtpConfigurations => Set<SmtpConfiguration>();
public DbSet<Notification> Notifications => Set<Notification>();
// Scripts
public DbSet<SharedScript> SharedScripts => Set<SharedScript>();