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
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using ControlCenter.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace ControlCenter.Data.Configurations;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core entity configuration for <see cref="AgentState"/>.
|
||||
///
|
||||
/// <para>Maps to the <c>agents</c> table with snake_case column naming,
|
||||
/// consistent with the Extrudex project conventions.</para>
|
||||
///
|
||||
/// <para>CUB-56 will create the migration; this configuration only
|
||||
/// defines the entity-to-table mapping and constraints.</para>
|
||||
/// </summary>
|
||||
public class AgentStateConfiguration : IEntityTypeConfiguration<AgentState>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<AgentState> builder)
|
||||
{
|
||||
// Table name
|
||||
builder.ToTable("agents");
|
||||
|
||||
// Primary key
|
||||
builder.HasKey(a => a.Id);
|
||||
|
||||
// Properties with snake_case column names
|
||||
builder.Property(a => a.Id)
|
||||
.HasColumnName("id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
builder.Property(a => a.Status)
|
||||
.HasColumnName("status")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasDefaultValue("idle");
|
||||
|
||||
builder.Property(a => a.Task)
|
||||
.HasColumnName("task")
|
||||
.IsRequired(false)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(a => a.Progress)
|
||||
.HasColumnName("progress")
|
||||
.IsRequired(false);
|
||||
|
||||
builder.Property(a => a.SessionKey)
|
||||
.HasColumnName("session_key")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255);
|
||||
|
||||
builder.Property(a => a.Channel)
|
||||
.HasColumnName("channel")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(a => a.LastActivity)
|
||||
.HasColumnName("last_activity")
|
||||
.IsRequired()
|
||||
.HasDefaultValueSql("NOW()");
|
||||
|
||||
// Indexes
|
||||
builder.HasIndex(a => a.SessionKey)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_agents_session_key");
|
||||
|
||||
builder.HasIndex(a => a.Status)
|
||||
.HasDatabaseName("ix_agents_status");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user