2026-06-09 11:58:20 +03:30
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using TeamUp.Modules.OrgBoard.Domain;
|
|
|
|
|
using TeamUp.SharedKernel.Persistence;
|
|
|
|
|
|
|
|
|
|
namespace TeamUp.Modules.OrgBoard.Persistence;
|
|
|
|
|
|
|
|
|
|
internal sealed class OrgBoardDbContext(DbContextOptions<OrgBoardDbContext> options)
|
|
|
|
|
: DbContext(options), IModuleDbContext
|
|
|
|
|
{
|
|
|
|
|
public DbSet<Organization> Organizations => Set<Organization>();
|
|
|
|
|
public DbSet<Team> Teams => Set<Team>();
|
|
|
|
|
public DbSet<Seat> Seats => Set<Seat>();
|
2026-06-09 23:49:28 +03:30
|
|
|
public DbSet<Agent> Agents => Set<Agent>();
|
2026-06-09 11:58:20 +03:30
|
|
|
public DbSet<WorkItem> WorkItems => Set<WorkItem>();
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
modelBuilder.HasDefaultSchema("orgboard");
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Organization>(organization =>
|
|
|
|
|
{
|
|
|
|
|
organization.ToTable("organizations");
|
|
|
|
|
organization.HasKey(o => o.Id);
|
|
|
|
|
organization.Property(o => o.Name).HasMaxLength(200).IsRequired();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Team>(team =>
|
|
|
|
|
{
|
|
|
|
|
team.ToTable("teams");
|
|
|
|
|
team.HasKey(t => t.Id);
|
|
|
|
|
team.Property(t => t.Name).HasMaxLength(200).IsRequired();
|
|
|
|
|
team.HasIndex(t => t.OrganizationId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Seat>(seat =>
|
|
|
|
|
{
|
|
|
|
|
seat.ToTable("seats");
|
|
|
|
|
seat.HasKey(s => s.Id);
|
|
|
|
|
seat.Property(s => s.RoleName).HasMaxLength(120).IsRequired();
|
|
|
|
|
seat.Property(s => s.State).HasConversion<string>().HasMaxLength(16);
|
|
|
|
|
seat.HasIndex(s => s.TeamId);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-09 23:49:28 +03:30
|
|
|
modelBuilder.Entity<Agent>(agent =>
|
|
|
|
|
{
|
|
|
|
|
agent.ToTable("agents");
|
|
|
|
|
agent.HasKey(a => a.Id);
|
|
|
|
|
agent.Property(a => a.Name).HasMaxLength(120).IsRequired();
|
|
|
|
|
agent.Property(a => a.Monogram).HasMaxLength(8);
|
|
|
|
|
agent.Property(a => a.Autonomy).HasConversion<string>().HasMaxLength(20);
|
|
|
|
|
agent.HasIndex(a => a.SeatId).IsUnique();
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-09 11:58:20 +03:30
|
|
|
modelBuilder.Entity<WorkItem>(workItem =>
|
|
|
|
|
{
|
|
|
|
|
workItem.ToTable("work_items");
|
|
|
|
|
workItem.HasKey(w => w.Id);
|
|
|
|
|
workItem.Property(w => w.Title).HasMaxLength(300).IsRequired();
|
|
|
|
|
workItem.Property(w => w.Type).HasConversion<string>().HasMaxLength(16);
|
|
|
|
|
workItem.Property(w => w.Status).HasConversion<string>().HasMaxLength(16);
|
|
|
|
|
workItem.Property(w => w.AssigneeKind).HasConversion<string>().HasMaxLength(16);
|
|
|
|
|
workItem.HasIndex(w => w.TeamId);
|
|
|
|
|
workItem.HasIndex(w => new { w.AssigneeKind, w.AssigneeId });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|