Phase 1 WP-1: EF Core DbContext with Fluent API mappings for all 26 entities
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.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using ScadaLink.Commons.Entities.Deployment;
|
||||
using ScadaLink.Commons.Entities.Instances;
|
||||
|
||||
namespace ScadaLink.ConfigurationDatabase.Configurations;
|
||||
|
||||
public class DeploymentRecordConfiguration : IEntityTypeConfiguration<DeploymentRecord>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<DeploymentRecord> 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<string>()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.HasOne<Instance>()
|
||||
.WithMany()
|
||||
.HasForeignKey(d => d.InstanceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
// Optimistic concurrency on deployment status records
|
||||
builder.Property<byte[]>("RowVersion")
|
||||
.IsRowVersion();
|
||||
|
||||
builder.HasIndex(d => d.DeploymentId).IsUnique();
|
||||
builder.HasIndex(d => d.InstanceId);
|
||||
builder.HasIndex(d => d.DeployedAt);
|
||||
}
|
||||
}
|
||||
|
||||
public class SystemArtifactDeploymentRecordConfiguration : IEntityTypeConfiguration<SystemArtifactDeploymentRecord>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<SystemArtifactDeploymentRecord> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user