Files
Control-Center/backend/ControlCenter/Data/Configurations/AgentStateConfiguration.cs

69 lines
2.0 KiB
C#
Raw Normal View History

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