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,81 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using ScadaLink.Commons.Entities.ExternalSystems;
|
||||
|
||||
namespace ScadaLink.ConfigurationDatabase.Configurations;
|
||||
|
||||
public class ExternalSystemDefinitionConfiguration : IEntityTypeConfiguration<ExternalSystemDefinition>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ExternalSystemDefinition> builder)
|
||||
{
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(e => e.EndpointUrl)
|
||||
.IsRequired()
|
||||
.HasMaxLength(2000);
|
||||
|
||||
builder.Property(e => e.AuthType)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(e => e.AuthConfiguration)
|
||||
.HasMaxLength(4000);
|
||||
|
||||
builder.HasMany<ExternalSystemMethod>()
|
||||
.WithOne()
|
||||
.HasForeignKey(m => m.ExternalSystemDefinitionId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(e => e.Name).IsUnique();
|
||||
}
|
||||
}
|
||||
|
||||
public class ExternalSystemMethodConfiguration : IEntityTypeConfiguration<ExternalSystemMethod>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ExternalSystemMethod> builder)
|
||||
{
|
||||
builder.HasKey(m => m.Id);
|
||||
|
||||
builder.Property(m => m.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(m => m.HttpMethod)
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.Property(m => m.Path)
|
||||
.IsRequired()
|
||||
.HasMaxLength(2000);
|
||||
|
||||
builder.Property(m => m.ParameterDefinitions)
|
||||
.HasMaxLength(4000);
|
||||
|
||||
builder.Property(m => m.ReturnDefinition)
|
||||
.HasMaxLength(4000);
|
||||
|
||||
builder.HasIndex(m => new { m.ExternalSystemDefinitionId, m.Name }).IsUnique();
|
||||
}
|
||||
}
|
||||
|
||||
public class DatabaseConnectionDefinitionConfiguration : IEntityTypeConfiguration<DatabaseConnectionDefinition>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<DatabaseConnectionDefinition> builder)
|
||||
{
|
||||
builder.HasKey(d => d.Id);
|
||||
|
||||
builder.Property(d => d.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(d => d.ConnectionString)
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000);
|
||||
|
||||
builder.HasIndex(d => d.Name).IsUnique();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user