Database improvement

1.  Separate configuration files
2.  Remove commented code
3.  Improve entity configurations (constraints, indexes, relationships)
This commit is contained in:
2025-12-04 08:09:01 -05:00
parent 2d5d075879
commit 826eac1372
8 changed files with 787 additions and 80 deletions
+37
View File
@@ -0,0 +1,37 @@
using Core.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Data.Configurations
{
public class TeamConfiguration : IEntityTypeConfiguration<Team>
{
public void Configure(EntityTypeBuilder<Team> builder)
{
builder.HasKey(t => t.Id);
// Indexes on shadow properties created by EF Core
builder.HasIndex("EventId");
builder.HasIndex("EventId", "Identifier");
// Constraints
builder.Property(t => t.Identifier)
.HasMaxLength(50);
// Relationships
builder.HasOne(t => t.Event)
.WithMany()
.IsRequired()
.OnDelete(DeleteBehavior.Restrict); // Don't delete teams when event is deleted
builder.HasMany(t => t.Students)
.WithMany(s => s.Teams)
.UsingEntity(j => j.ToTable("TeamStudents")); // Explicit table name
builder.HasOne(t => t.Captain)
.WithMany()
.IsRequired(false)
.OnDelete(DeleteBehavior.SetNull); // Set to null if captain is deleted
}
}
}