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.
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using ScadaLink.Commons.Entities.InboundApi;
|
|
|
|
namespace ScadaLink.ConfigurationDatabase.Configurations;
|
|
|
|
public class ApiKeyConfiguration : IEntityTypeConfiguration<ApiKey>
|
|
{
|
|
public void Configure(EntityTypeBuilder<ApiKey> builder)
|
|
{
|
|
builder.HasKey(k => k.Id);
|
|
|
|
builder.Property(k => k.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(k => k.KeyValue)
|
|
.IsRequired()
|
|
.HasMaxLength(500);
|
|
|
|
builder.HasIndex(k => k.Name).IsUnique();
|
|
builder.HasIndex(k => k.KeyValue).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class ApiMethodConfiguration : IEntityTypeConfiguration<ApiMethod>
|
|
{
|
|
public void Configure(EntityTypeBuilder<ApiMethod> builder)
|
|
{
|
|
builder.HasKey(m => m.Id);
|
|
|
|
builder.Property(m => m.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(m => m.Script)
|
|
.IsRequired();
|
|
|
|
builder.Property(m => m.ApprovedApiKeyIds)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.Property(m => m.ParameterDefinitions)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.Property(m => m.ReturnDefinition)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.HasIndex(m => m.Name).IsUnique();
|
|
}
|
|
}
|