1eb6e972b0
Bulk CommentChecker pass: fills in <param>/<inheritdoc> tags on public APIs across all 23 src/ projects so the doc-coverage gate is green. Also adds a Sister Projects section to CLAUDE.md pointing at the MxAccess Gateway and OtOpcUa sibling repos, and gitignores local credential captures (*login*.txt) and the wonder-app-vd03 deploy/ artifacts.
194 lines
6.3 KiB
C#
194 lines
6.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using ScadaLink.Commons.Entities.Templates;
|
|
|
|
namespace ScadaLink.ConfigurationDatabase.Configurations;
|
|
|
|
public class TemplateConfiguration : IEntityTypeConfiguration<Template>
|
|
{
|
|
/// <summary>Configures the EF Core mapping for <see cref="Template"/>.</summary>
|
|
/// <param name="builder">The entity type builder.</param>
|
|
public void Configure(EntityTypeBuilder<Template> builder)
|
|
{
|
|
builder.HasKey(t => t.Id);
|
|
|
|
builder.Property(t => t.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(t => t.Description)
|
|
.HasMaxLength(2000);
|
|
|
|
// Only base (user-authored) templates are globally unique by name.
|
|
// Derived templates store their *contained* name (the composition slot's
|
|
// InstanceName), unique only within the owner — enforced by the
|
|
// (TemplateId, InstanceName) index on TemplateComposition — so they are
|
|
// excluded from this index via a filter.
|
|
builder.HasIndex(t => t.Name).IsUnique().HasFilter("[IsDerived] = 0");
|
|
|
|
// Self-referencing parent template (inheritance)
|
|
builder.HasOne<Template>()
|
|
.WithMany()
|
|
.HasForeignKey(t => t.ParentTemplateId)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.IsRequired(false);
|
|
|
|
builder.HasOne<TemplateFolder>()
|
|
.WithMany()
|
|
.HasForeignKey(t => t.FolderId)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.IsRequired(false);
|
|
|
|
builder.HasMany(t => t.Attributes)
|
|
.WithOne()
|
|
.HasForeignKey(a => a.TemplateId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder.HasMany(t => t.Alarms)
|
|
.WithOne()
|
|
.HasForeignKey(a => a.TemplateId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder.HasMany(t => t.Scripts)
|
|
.WithOne()
|
|
.HasForeignKey(s => s.TemplateId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder.HasMany(t => t.Compositions)
|
|
.WithOne()
|
|
.HasForeignKey(c => c.TemplateId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|
|
|
|
public class TemplateAttributeConfiguration : IEntityTypeConfiguration<TemplateAttribute>
|
|
{
|
|
/// <summary>Configures the EF Core mapping for <see cref="TemplateAttribute"/>.</summary>
|
|
/// <param name="builder">The entity type builder.</param>
|
|
public void Configure(EntityTypeBuilder<TemplateAttribute> builder)
|
|
{
|
|
builder.HasKey(a => a.Id);
|
|
|
|
builder.Property(a => a.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(a => a.Value)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.Property(a => a.Description)
|
|
.HasMaxLength(2000);
|
|
|
|
builder.Property(a => a.DataSourceReference)
|
|
.HasMaxLength(500);
|
|
|
|
builder.Property(a => a.DataType)
|
|
.HasConversion<string>()
|
|
.HasMaxLength(50);
|
|
|
|
builder.HasIndex(a => new { a.TemplateId, a.Name }).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class TemplateAlarmConfiguration : IEntityTypeConfiguration<TemplateAlarm>
|
|
{
|
|
/// <summary>Configures the EF Core mapping for <see cref="TemplateAlarm"/>.</summary>
|
|
/// <param name="builder">The entity type builder.</param>
|
|
public void Configure(EntityTypeBuilder<TemplateAlarm> builder)
|
|
{
|
|
builder.HasKey(a => a.Id);
|
|
|
|
builder.Property(a => a.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(a => a.Description)
|
|
.HasMaxLength(2000);
|
|
|
|
builder.Property(a => a.TriggerType)
|
|
.HasConversion<string>()
|
|
.HasMaxLength(50);
|
|
|
|
builder.Property(a => a.TriggerConfiguration)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.HasIndex(a => new { a.TemplateId, a.Name }).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class TemplateScriptConfiguration : IEntityTypeConfiguration<TemplateScript>
|
|
{
|
|
/// <summary>Configures the EF Core mapping for <see cref="TemplateScript"/>.</summary>
|
|
/// <param name="builder">The entity type builder.</param>
|
|
public void Configure(EntityTypeBuilder<TemplateScript> builder)
|
|
{
|
|
builder.HasKey(s => s.Id);
|
|
|
|
builder.Property(s => s.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(s => s.Code)
|
|
.IsRequired();
|
|
|
|
builder.Property(s => s.TriggerType)
|
|
.HasMaxLength(50);
|
|
|
|
builder.Property(s => s.TriggerConfiguration)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.Property(s => s.ParameterDefinitions)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.Property(s => s.ReturnDefinition)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.HasIndex(s => new { s.TemplateId, s.Name }).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class TemplateCompositionConfiguration : IEntityTypeConfiguration<TemplateComposition>
|
|
{
|
|
/// <summary>Configures the EF Core mapping for <see cref="TemplateComposition"/>.</summary>
|
|
/// <param name="builder">The entity type builder.</param>
|
|
public void Configure(EntityTypeBuilder<TemplateComposition> builder)
|
|
{
|
|
builder.HasKey(c => c.Id);
|
|
|
|
builder.Property(c => c.InstanceName)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
// The composed template reference
|
|
builder.HasOne<Template>()
|
|
.WithMany()
|
|
.HasForeignKey(c => c.ComposedTemplateId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasIndex(c => new { c.TemplateId, c.InstanceName }).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class TemplateFolderConfiguration : IEntityTypeConfiguration<TemplateFolder>
|
|
{
|
|
/// <summary>Configures the EF Core mapping for <see cref="TemplateFolder"/>.</summary>
|
|
/// <param name="builder">The entity type builder.</param>
|
|
public void Configure(EntityTypeBuilder<TemplateFolder> builder)
|
|
{
|
|
builder.HasKey(f => f.Id);
|
|
|
|
builder.Property(f => f.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.HasOne<TemplateFolder>()
|
|
.WithMany()
|
|
.HasForeignKey(f => f.ParentFolderId)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.IsRequired(false);
|
|
|
|
// Unique sibling name (case-insensitive enforced at service layer; this index is for fast lookup)
|
|
builder.HasIndex(f => new { f.ParentFolderId, f.Name }).IsUnique();
|
|
}
|
|
}
|