Files
Control-Center/backend/ControlCenter/Data/ControlCenterDbContext.cs
cubecraft-agents[bot] eb08a0bc90 CUB-54: implement AgentState entity, repository, and DI registration
- Add AgentState entity mapping to 'agents' table (snake_case columns)
- Add IAgentStateRepository interface (GetAllAsync, GetBySessionKeyAsync, UpdateStatusAsync)
- Add AgentStateRepository with EF Core implementation
- Add ControlCenterDbContext with ApplyConfigurationsFromAssembly
- Add AgentStateConfiguration with snake_case column mappings and indexes
- Register DbContext (Npgsql) and repository in Program.cs DI
- Add ConnectionStrings to appsettings.json
- Add EF Core 9.0.7 and Npgsql.EntityFrameworkCore.PostgreSQL 9.0.4 packages
2026-04-26 11:44:17 +00:00

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);
}
}