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
@@ -0,0 +1,279 @@
// <auto-generated />
using Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Data.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20251204130505_ConfigurationRefactor")]
partial class ConfigurationRefactor
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.8");
modelBuilder.Entity("Core.Entities.EventDefinition", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("ChapterEligibilityCountRegionals")
.HasColumnType("INTEGER");
b.Property<int>("ChapterEligibilityCountState")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.HasMaxLength(1000)
.HasColumnType("TEXT");
b.Property<string>("Documentation")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Eligibility")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("EventFormat")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int?>("LevelOfEffort")
.HasColumnType("INTEGER");
b.Property<int>("MaxTeamSize")
.HasColumnType("INTEGER");
b.Property<int>("MinTeamSize")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Notes")
.HasMaxLength(1024)
.HasColumnType("TEXT");
b.Property<bool>("OnSiteActivity")
.HasColumnType("INTEGER");
b.Property<bool>("Presubmission")
.HasColumnType("INTEGER");
b.Property<string>("SemifinalistActivity")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("ShortName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Theme")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("EventFormat");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Events");
});
modelBuilder.Entity("Core.Entities.Student", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Email")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("FirstName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<int>("Grade")
.HasColumnType("INTEGER");
b.Property<string>("LastName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("NationalId")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("OfficerRole")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasMaxLength(20)
.HasColumnType("TEXT");
b.Property<string>("RegionalId")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("StateId")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("TsaYear")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("Email");
b.HasIndex("Grade");
b.HasIndex("FirstName", "LastName");
b.ToTable("Students");
});
modelBuilder.Entity("Core.Entities.StudentEventRanking", b =>
{
b.Property<int>("StudentId")
.HasColumnType("INTEGER");
b.Property<int>("EventDefinitionId")
.HasColumnType("INTEGER");
b.Property<int>("Rank")
.HasColumnType("INTEGER");
b.HasKey("StudentId", "EventDefinitionId");
b.HasIndex("EventDefinitionId");
b.HasIndex("Rank");
b.HasIndex("StudentId");
b.ToTable("StudentEventRanking");
});
modelBuilder.Entity("Core.Entities.Team", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("CaptainId")
.HasColumnType("INTEGER");
b.Property<int>("EventId")
.HasColumnType("INTEGER");
b.Property<string>("Identifier")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CaptainId");
b.HasIndex("EventId");
b.HasIndex("EventId", "Identifier");
b.ToTable("Teams");
});
modelBuilder.Entity("StudentTeam", b =>
{
b.Property<int>("StudentsId")
.HasColumnType("INTEGER");
b.Property<int>("TeamsId")
.HasColumnType("INTEGER");
b.HasKey("StudentsId", "TeamsId");
b.HasIndex("TeamsId");
b.ToTable("TeamStudents", (string)null);
});
modelBuilder.Entity("Core.Entities.StudentEventRanking", b =>
{
b.HasOne("Core.Entities.EventDefinition", "EventDefinition")
.WithMany()
.HasForeignKey("EventDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Core.Entities.Student", "Student")
.WithMany("EventRankings")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("EventDefinition");
b.Navigation("Student");
});
modelBuilder.Entity("Core.Entities.Team", b =>
{
b.HasOne("Core.Entities.Student", "Captain")
.WithMany()
.HasForeignKey("CaptainId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("Core.Entities.EventDefinition", "Event")
.WithMany()
.HasForeignKey("EventId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Captain");
b.Navigation("Event");
});
modelBuilder.Entity("StudentTeam", b =>
{
b.HasOne("Core.Entities.Student", null)
.WithMany()
.HasForeignKey("StudentsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Core.Entities.Team", null)
.WithMany()
.HasForeignKey("TeamsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Core.Entities.Student", b =>
{
b.Navigation("EventRankings");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,287 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.Migrations
{
/// <inheritdoc />
public partial class ConfigurationRefactor : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_StudentTeam_Students_StudentsId",
table: "StudentTeam");
migrationBuilder.DropForeignKey(
name: "FK_StudentTeam_Teams_TeamsId",
table: "StudentTeam");
migrationBuilder.DropForeignKey(
name: "FK_Teams_Events_EventId",
table: "Teams");
migrationBuilder.DropForeignKey(
name: "FK_Teams_Students_CaptainId",
table: "Teams");
migrationBuilder.DropPrimaryKey(
name: "PK_StudentEventRanking",
table: "StudentEventRanking");
migrationBuilder.DropIndex(
name: "IX_Events_Name",
table: "Events");
migrationBuilder.DropPrimaryKey(
name: "PK_StudentTeam",
table: "StudentTeam");
migrationBuilder.RenameTable(
name: "StudentTeam",
newName: "TeamStudents");
migrationBuilder.RenameIndex(
name: "IX_StudentTeam_TeamsId",
table: "TeamStudents",
newName: "IX_TeamStudents_TeamsId");
migrationBuilder.AlterColumn<string>(
name: "OfficerRole",
table: "Students",
type: "TEXT",
maxLength: 50,
nullable: true,
oldClrType: typeof(int),
oldType: "INTEGER",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "EventFormat",
table: "Events",
type: "TEXT",
maxLength: 50,
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER");
migrationBuilder.AddPrimaryKey(
name: "PK_StudentEventRanking",
table: "StudentEventRanking",
columns: new[] { "StudentId", "EventDefinitionId" });
migrationBuilder.AddPrimaryKey(
name: "PK_TeamStudents",
table: "TeamStudents",
columns: new[] { "StudentsId", "TeamsId" });
migrationBuilder.CreateIndex(
name: "IX_Teams_EventId_Identifier",
table: "Teams",
columns: new[] { "EventId", "Identifier" });
migrationBuilder.CreateIndex(
name: "IX_Students_Email",
table: "Students",
column: "Email");
migrationBuilder.CreateIndex(
name: "IX_Students_FirstName_LastName",
table: "Students",
columns: new[] { "FirstName", "LastName" });
migrationBuilder.CreateIndex(
name: "IX_Students_Grade",
table: "Students",
column: "Grade");
migrationBuilder.CreateIndex(
name: "IX_StudentEventRanking_EventDefinitionId",
table: "StudentEventRanking",
column: "EventDefinitionId");
migrationBuilder.CreateIndex(
name: "IX_StudentEventRanking_Rank",
table: "StudentEventRanking",
column: "Rank");
migrationBuilder.CreateIndex(
name: "IX_Events_EventFormat",
table: "Events",
column: "EventFormat");
migrationBuilder.CreateIndex(
name: "IX_Events_Name",
table: "Events",
column: "Name",
unique: true);
migrationBuilder.AddForeignKey(
name: "FK_Teams_Events_EventId",
table: "Teams",
column: "EventId",
principalTable: "Events",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Teams_Students_CaptainId",
table: "Teams",
column: "CaptainId",
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
migrationBuilder.AddForeignKey(
name: "FK_TeamStudents_Students_StudentsId",
table: "TeamStudents",
column: "StudentsId",
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_TeamStudents_Teams_TeamsId",
table: "TeamStudents",
column: "TeamsId",
principalTable: "Teams",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Teams_Events_EventId",
table: "Teams");
migrationBuilder.DropForeignKey(
name: "FK_Teams_Students_CaptainId",
table: "Teams");
migrationBuilder.DropForeignKey(
name: "FK_TeamStudents_Students_StudentsId",
table: "TeamStudents");
migrationBuilder.DropForeignKey(
name: "FK_TeamStudents_Teams_TeamsId",
table: "TeamStudents");
migrationBuilder.DropIndex(
name: "IX_Teams_EventId_Identifier",
table: "Teams");
migrationBuilder.DropIndex(
name: "IX_Students_Email",
table: "Students");
migrationBuilder.DropIndex(
name: "IX_Students_FirstName_LastName",
table: "Students");
migrationBuilder.DropIndex(
name: "IX_Students_Grade",
table: "Students");
migrationBuilder.DropPrimaryKey(
name: "PK_StudentEventRanking",
table: "StudentEventRanking");
migrationBuilder.DropIndex(
name: "IX_StudentEventRanking_EventDefinitionId",
table: "StudentEventRanking");
migrationBuilder.DropIndex(
name: "IX_StudentEventRanking_Rank",
table: "StudentEventRanking");
migrationBuilder.DropIndex(
name: "IX_Events_EventFormat",
table: "Events");
migrationBuilder.DropIndex(
name: "IX_Events_Name",
table: "Events");
migrationBuilder.DropPrimaryKey(
name: "PK_TeamStudents",
table: "TeamStudents");
migrationBuilder.RenameTable(
name: "TeamStudents",
newName: "StudentTeam");
migrationBuilder.RenameIndex(
name: "IX_TeamStudents_TeamsId",
table: "StudentTeam",
newName: "IX_StudentTeam_TeamsId");
migrationBuilder.AlterColumn<int>(
name: "OfficerRole",
table: "Students",
type: "INTEGER",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 50,
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "EventFormat",
table: "Events",
type: "INTEGER",
nullable: false,
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 50);
migrationBuilder.AddPrimaryKey(
name: "PK_StudentEventRanking",
table: "StudentEventRanking",
columns: new[] { "EventDefinitionId", "StudentId" });
migrationBuilder.AddPrimaryKey(
name: "PK_StudentTeam",
table: "StudentTeam",
columns: new[] { "StudentsId", "TeamsId" });
migrationBuilder.CreateIndex(
name: "IX_Events_Name",
table: "Events",
column: "Name");
migrationBuilder.AddForeignKey(
name: "FK_StudentTeam_Students_StudentsId",
table: "StudentTeam",
column: "StudentsId",
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_StudentTeam_Teams_TeamsId",
table: "StudentTeam",
column: "TeamsId",
principalTable: "Teams",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Teams_Events_EventId",
table: "Teams",
column: "EventId",
principalTable: "Events",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Teams_Students_CaptainId",
table: "Teams",
column: "CaptainId",
principalTable: "Students",
principalColumn: "Id");
}
}
}
+44 -20
View File
@@ -29,20 +29,22 @@ namespace Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Description")
.HasMaxLength(1024)
.HasMaxLength(1000)
.HasColumnType("TEXT");
b.Property<string>("Documentation")
.HasMaxLength(64)
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Eligibility")
.IsRequired()
.HasMaxLength(256)
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<int>("EventFormat")
.HasColumnType("INTEGER");
b.Property<string>("EventFormat")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int?>("LevelOfEffort")
.HasColumnType("INTEGER");
@@ -69,21 +71,24 @@ namespace Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("SemifinalistActivity")
.HasMaxLength(100)
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("ShortName")
.IsRequired()
.HasMaxLength(40)
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Theme")
.HasMaxLength(4096)
.HasMaxLength(500)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Name");
b.HasIndex("EventFormat");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Events");
});
@@ -95,11 +100,12 @@ namespace Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Email")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("FirstName")
.IsRequired()
.HasMaxLength(50)
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<int>("Grade")
@@ -107,22 +113,27 @@ namespace Data.Migrations
b.Property<string>("LastName")
.IsRequired()
.HasMaxLength(50)
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("NationalId")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int?>("OfficerRole")
.HasColumnType("INTEGER");
b.Property<string>("OfficerRole")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasMaxLength(20)
.HasColumnType("TEXT");
b.Property<string>("RegionalId")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("StateId")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("TsaYear")
@@ -130,21 +141,31 @@ namespace Data.Migrations
b.HasKey("Id");
b.HasIndex("Email");
b.HasIndex("Grade");
b.HasIndex("FirstName", "LastName");
b.ToTable("Students");
});
modelBuilder.Entity("Core.Entities.StudentEventRanking", b =>
{
b.Property<int>("EventDefinitionId")
b.Property<int>("StudentId")
.HasColumnType("INTEGER");
b.Property<int>("StudentId")
b.Property<int>("EventDefinitionId")
.HasColumnType("INTEGER");
b.Property<int>("Rank")
.HasColumnType("INTEGER");
b.HasKey("EventDefinitionId", "StudentId");
b.HasKey("StudentId", "EventDefinitionId");
b.HasIndex("EventDefinitionId");
b.HasIndex("Rank");
b.HasIndex("StudentId");
@@ -164,7 +185,7 @@ namespace Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Identifier")
.HasMaxLength(32)
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
@@ -173,6 +194,8 @@ namespace Data.Migrations
b.HasIndex("EventId");
b.HasIndex("EventId", "Identifier");
b.ToTable("Teams");
});
@@ -188,7 +211,7 @@ namespace Data.Migrations
b.HasIndex("TeamsId");
b.ToTable("StudentTeam");
b.ToTable("TeamStudents", (string)null);
});
modelBuilder.Entity("Core.Entities.StudentEventRanking", b =>
@@ -214,12 +237,13 @@ namespace Data.Migrations
{
b.HasOne("Core.Entities.Student", "Captain")
.WithMany()
.HasForeignKey("CaptainId");
.HasForeignKey("CaptainId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("Core.Entities.EventDefinition", "Event")
.WithMany()
.HasForeignKey("EventId")
.OnDelete(DeleteBehavior.Cascade)
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Captain");