39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
|
|
using ControlCenter.Models;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
|
||
|
|
namespace ControlCenter.Data;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// EF Core DbContext for the Control Center database.
|
||
|
|
///
|
||
|
|
/// <para>Provides <see cref="DbSet{T}"/> access to all persistent entities.
|
||
|
|
/// Uses snake_case naming conventions for PostgreSQL columns,
|
||
|
|
/// applied via <see cref="Configurations.AgentStateConfiguration"/>.</para>
|
||
|
|
///
|
||
|
|
/// <para>Connection string is configured in <c>appsettings.json</c>
|
||
|
|
/// under <c>ConnectionStrings:ControlCenterDb</c>.</para>
|
||
|
|
/// </summary>
|
||
|
|
public class ControlCenterDbContext : DbContext
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Agent state records — one row per active or recently active agent.
|
||
|
|
/// Maps to the <c>agents</c> table.
|
||
|
|
/// </summary>
|
||
|
|
public DbSet<AgentState> AgentStates => Set<AgentState>();
|
||
|
|
|
||
|
|
public ControlCenterDbContext(DbContextOptions<ControlCenterDbContext> options)
|
||
|
|
: base(options)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||
|
|
{
|
||
|
|
// Apply all entity configurations from this assembly
|
||
|
|
modelBuilder.ApplyConfigurationsFromAssembly(
|
||
|
|
typeof(Configurations.AgentStateConfiguration).Assembly);
|
||
|
|
|
||
|
|
// Global snake_case naming convention for any unmapped columns
|
||
|
|
// (explicit configurations take precedence)
|
||
|
|
base.OnModelCreating(modelBuilder);
|
||
|
|
}
|
||
|
|
}
|