using Microsoft.EntityFrameworkCore; using TeamUp.Modules.OrgBoard.Domain; using TeamUp.SharedKernel.Persistence; namespace TeamUp.Modules.OrgBoard.Persistence; internal sealed class OrgBoardDbContext(DbContextOptions options) : DbContext(options), IModuleDbContext { public DbSet Organizations => Set(); public DbSet Teams => Set(); public DbSet Seats => Set(); public DbSet Agents => Set(); public DbSet WorkItems => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.HasDefaultSchema("orgboard"); modelBuilder.Entity(organization => { organization.ToTable("organizations"); organization.HasKey(o => o.Id); organization.Property(o => o.Name).HasMaxLength(200).IsRequired(); }); modelBuilder.Entity(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.ToTable("seats"); seat.HasKey(s => s.Id); seat.Property(s => s.RoleName).HasMaxLength(120).IsRequired(); seat.Property(s => s.State).HasConversion().HasMaxLength(16); seat.HasIndex(s => s.TeamId); }); modelBuilder.Entity(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().HasMaxLength(20); agent.HasIndex(a => a.SeatId).IsUnique(); }); modelBuilder.Entity(workItem => { workItem.ToTable("work_items"); workItem.HasKey(w => w.Id); workItem.Property(w => w.Title).HasMaxLength(300).IsRequired(); workItem.Property(w => w.Type).HasConversion().HasMaxLength(16); workItem.Property(w => w.Status).HasConversion().HasMaxLength(16); workItem.Property(w => w.AssigneeKind).HasConversion().HasMaxLength(16); workItem.HasIndex(w => w.TeamId); workItem.HasIndex(w => new { w.AssigneeKind, w.AssigneeId }); }); } }