This commit is contained in:
2025-10-27 17:39:18 -04:00
commit 31f723bea4
1579 changed files with 642409 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Prefab.Data.Entities;
namespace Prefab.Data.Configs
{
/// <summary>
/// Entity Framework Core configuration for the <see cref="AuditLog"/> entity.
/// </summary>
public class AuditLogConfig() : Prefab.Data.Configs.EntityConfig<AuditLog>(nameof(IPrefabDb.AuditLogs))
{
/// <summary>
/// Configures the properties and relationships for the <see cref="AuditLog"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity type.</param>
public override void Configure(EntityTypeBuilder<AuditLog> builder)
{
builder.HasKey(e => e.Id);
builder.Property(e => e.Entity)
.HasMaxLength(Rules.EntityMaxLength)
.IsRequired();
builder.Property(e => e.State)
.IsRequired();
builder.Property(e => e.CreatedBy)
.IsRequired();
builder.Property(e => e.CreatedOn)
.IsRequired();
builder.HasMany(e => e.Items)
.WithOne(i => i.AuditLog)
.HasForeignKey(i => i.AuditLogId)
.OnDelete(DeleteBehavior.Cascade);
}
/// <summary>
/// Validation rules and settings for <see cref="AuditLog"/> properties.
/// </summary>
public static class Rules
{
/// <summary>Maximum length for the Entity name.</summary>
public const int EntityMaxLength = 200;
}
}
}

View File

@@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Prefab.Data.Entities;
namespace Prefab.Data.Configs
{
/// <summary>
/// Entity Framework Core configuration for the <see cref="AuditLogItem"/> entity.
/// </summary>
public class AuditLogItemConfig() : Prefab.Data.Configs.EntityConfig<AuditLogItem>(nameof(IPrefabDb.AuditLogItems))
{
/// <summary>
/// Configures the properties and relationships for the <see cref="AuditLogItem"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity type.</param>
public override void Configure(EntityTypeBuilder<AuditLogItem> builder)
{
builder.HasKey(e => e.Id);
builder.Property(e => e.Property)
.HasMaxLength(Rules.PropertyMaxLength)
.IsRequired();
builder.Property(e => e.OldValue)
.HasMaxLength(Rules.ValueMaxLength);
builder.Property(e => e.NewValue)
.HasMaxLength(Rules.ValueMaxLength);
builder.HasOne(e => e.AuditLog)
.WithMany(a => a.Items)
.HasForeignKey(e => e.AuditLogId)
.OnDelete(DeleteBehavior.Cascade);
}
/// <summary>
/// Validation rules and settings for <see cref="AuditLogItem"/> properties.
/// </summary>
public static class Rules
{
/// <summary>Maximum length for the property name.</summary>
public const int PropertyMaxLength = 100;
/// <summary>Maximum length for the value fields.</summary>
public const int ValueMaxLength = 1000;
}
}
}

View File

@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Prefab.Data.Configs
{
/// <summary>
/// Base configuration for all entities, sets items like table name and schema.
/// </summary>
/// <typeparam name="T">The entity type.</typeparam>
public abstract class EntityConfig<T> : IEntityTypeConfiguration<T> where T : class
{
private readonly string _schema;
private readonly string _tableName;
protected EntityConfig(string tableName, string? schema = null)
{
ArgumentException.ThrowIfNullOrWhiteSpace(tableName);
_tableName = tableName;
_schema = string.IsNullOrWhiteSpace(schema) ? "dbo" : schema;
}
public virtual void Configure(EntityTypeBuilder<T> builder)
{
builder.ToTable(_tableName, _schema);
}
}
}

View File

@@ -0,0 +1,72 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Prefab.Data.Entities;
namespace Prefab.Data.Configs;
/// <summary>
/// Configuration class for the <see cref="GenericAttribute"/> entity within the dbo schema.
/// </summary>
public class GenericAttributeConfig() : EntityConfig<GenericAttribute>(nameof(IPrefabDb.GenericAttributes))
{
/// <summary>
/// Configuration of Entity Framework mapping for the <see cref="GenericAttribute"/> entity.
/// </summary>
public override void Configure(EntityTypeBuilder<GenericAttribute> builder)
{
builder
.Ignore(x => x.Id);
// Define the composite key (and clustered index) for the GenericAttribute entity.
builder
.HasKey(x => new { x.EntityId, x.KeyGroup, x.Key });
builder.HasIndex(x => new { x.EntityId, x.KeyGroup })
.HasDatabaseName("IX_GenericAttributes_Entity_Group");
builder.HasIndex(x => x.DeletedOn)
.HasFilter("[DeletedOn] IS NULL")
.HasDatabaseName("IX_GenericAttributes_Active");
builder
.Property(x => x.KeyGroup)
.HasMaxLength(Rules.KeyGroupMaxLength)
.IsRequired();
builder
.Property(x => x.Key)
.HasMaxLength(Rules.KeyMaxLength)
.IsRequired();
builder
.Property(x => x.Value)
.HasMaxLength(Rules.ValueMaxLength)
.IsRequired();
}
/// <summary>
/// Validation rules for the <see cref="GenericAttribute"/> entity.
/// </summary>
public static class Rules
{
/// <summary>
/// Maximum length to set for the generic attribute key group.
/// </summary>
public const int KeyGroupMaxLength = 400;
/// <summary>
/// Minimum length to set for the generic attribute key.
/// </summary>
public const int KeyMinLength = 3;
/// <summary>
/// Maximum length to set for the generic attribute key.
/// </summary>
public const int KeyMaxLength = 400;
/// <summary>
/// Maximum length to set for the generic attribute value.
/// </summary>
public const int ValueMaxLength = int.MaxValue;
}
}

View File

@@ -0,0 +1,53 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Prefab.Data.Entities;
namespace Prefab.Data.Configs;
/// <summary>
/// Configuration class for the <see cref="SeederLog"/> entity.
/// </summary>
public class SeederLogConfig() : Prefab.Data.Configs.EntityConfig<SeederLog>(nameof(IPrefabDb.SeederLogs))
{
/// <summary>
/// Configuration of Entity Framework mapping for the <see cref="SeederLog"/> entity.
/// </summary>
public override void Configure(EntityTypeBuilder<SeederLog> builder)
{
ArgumentNullException.ThrowIfNull(builder);
builder
.HasKey(x => x.Id);
builder
.Property(x => x.Id)
.ValueGeneratedOnAdd();
builder.Property(x => x.SeederName)
.HasMaxLength(Rules.SeederNameMaxLength)
.IsRequired();
builder.Property(x => x.RunMode)
.HasMaxLength(Rules.SeederRunModeMaxLength)
.IsRequired();
builder
.Property(x => x.RunAt)
.IsRequired();
}
/// <summary>
/// Validation rules for the <see cref="SeederLog"/> entity.
/// </summary>
public static class Rules
{
/// <summary>
/// Maximum length to set for the seeder name.
/// </summary>
public const int SeederNameMaxLength = 256;
/// <summary>
/// Maximum length to set for the seeder name.
/// </summary>
public const int SeederRunModeMaxLength = 64;
}
}