using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using ZB.MOM.WW.ScadaBridge.Commons.Entities.Deployment; using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances; namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Configurations; public class DeploymentRecordConfiguration : IEntityTypeConfiguration { /// Configures the EF Core mapping for . /// The entity type builder. public void Configure(EntityTypeBuilder builder) { builder.HasKey(d => d.Id); builder.Property(d => d.DeploymentId) .IsRequired() .HasMaxLength(100); builder.Property(d => d.RevisionHash) .HasMaxLength(100); builder.Property(d => d.DeployedBy) .IsRequired() .HasMaxLength(200); builder.Property(d => d.Status) .HasConversion() .HasMaxLength(50); builder.HasOne() .WithMany() .HasForeignKey(d => d.InstanceId) .OnDelete(DeleteBehavior.Restrict); // Optimistic concurrency on deployment status records builder.Property("RowVersion") .IsRowVersion(); builder.HasIndex(d => d.DeploymentId).IsUnique(); builder.HasIndex(d => d.InstanceId); builder.HasIndex(d => d.DeployedAt); } } public class DeployedConfigSnapshotConfiguration : IEntityTypeConfiguration { /// Configures the EF Core mapping for . /// The entity type builder. public void Configure(EntityTypeBuilder builder) { builder.HasKey(s => s.Id); builder.Property(s => s.DeploymentId) .IsRequired() .HasMaxLength(100); builder.Property(s => s.RevisionHash) .IsRequired() .HasMaxLength(100); builder.Property(s => s.ConfigurationJson) .IsRequired(); builder.HasOne() .WithMany() .HasForeignKey(s => s.InstanceId) .OnDelete(DeleteBehavior.Cascade); builder.HasIndex(s => s.InstanceId).IsUnique(); builder.HasIndex(s => s.DeploymentId); } } public class SystemArtifactDeploymentRecordConfiguration : IEntityTypeConfiguration { /// Configures the EF Core mapping for . /// The entity type builder. public void Configure(EntityTypeBuilder builder) { builder.HasKey(d => d.Id); builder.Property(d => d.ArtifactType) .IsRequired() .HasMaxLength(100); builder.Property(d => d.DeployedBy) .IsRequired() .HasMaxLength(200); builder.Property(d => d.PerSiteStatus) .HasMaxLength(4000); builder.HasIndex(d => d.DeployedAt); } }