1996b21961
ScadaLinkDbContext with 10 configuration classes (Fluent API only), initial migration creating 25 tables, environment-aware migration helper (auto-apply dev, validate-only prod), DesignTimeDbContextFactory, optimistic concurrency on DeploymentRecord. 20 tests verify schema, CRUD, relationships, cascades.
67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using ScadaLink.Commons.Entities.Notifications;
|
|
|
|
namespace ScadaLink.ConfigurationDatabase.Configurations;
|
|
|
|
public class NotificationListConfiguration : IEntityTypeConfiguration<NotificationList>
|
|
{
|
|
public void Configure(EntityTypeBuilder<NotificationList> builder)
|
|
{
|
|
builder.HasKey(n => n.Id);
|
|
|
|
builder.Property(n => n.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.HasMany(n => n.Recipients)
|
|
.WithOne()
|
|
.HasForeignKey(r => r.NotificationListId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder.HasIndex(n => n.Name).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class NotificationRecipientConfiguration : IEntityTypeConfiguration<NotificationRecipient>
|
|
{
|
|
public void Configure(EntityTypeBuilder<NotificationRecipient> builder)
|
|
{
|
|
builder.HasKey(r => r.Id);
|
|
|
|
builder.Property(r => r.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(r => r.EmailAddress)
|
|
.IsRequired()
|
|
.HasMaxLength(500);
|
|
}
|
|
}
|
|
|
|
public class SmtpConfigurationConfiguration : IEntityTypeConfiguration<SmtpConfiguration>
|
|
{
|
|
public void Configure(EntityTypeBuilder<SmtpConfiguration> builder)
|
|
{
|
|
builder.HasKey(s => s.Id);
|
|
|
|
builder.Property(s => s.Host)
|
|
.IsRequired()
|
|
.HasMaxLength(500);
|
|
|
|
builder.Property(s => s.AuthType)
|
|
.IsRequired()
|
|
.HasMaxLength(50);
|
|
|
|
builder.Property(s => s.Credentials)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.Property(s => s.TlsMode)
|
|
.HasMaxLength(50);
|
|
|
|
builder.Property(s => s.FromAddress)
|
|
.IsRequired()
|
|
.HasMaxLength(500);
|
|
}
|
|
}
|