学业预警

This commit is contained in:
2026-07-25 17:14:20 +08:00 Unverified
parent 5e4c76a9e4
commit db3a275601
8 changed files with 536 additions and 0 deletions
@@ -42,6 +42,8 @@ public sealed class DevelopmentSqliteMigrator(
"20260725_23_attendance_appeal";
private const string ApprovalTablesMigration =
"20260725_24_approval_tables";
private const string AcademicWarningsMigration =
"20260725_25_academic_warnings";
public async Task MigrateAsync(CancellationToken cancellationToken = default)
{
@@ -280,6 +282,14 @@ public sealed class DevelopmentSqliteMigrator(
ApprovalTablesMigration,
approvalTablesExist ? [] : ApprovalTableStatements,
cancellationToken);
var warningRulesExist = await db.Database
.SqlQueryRaw<int>("SELECT COUNT(*) AS \"Value\" FROM sqlite_master WHERE type = 'table' AND name = 'WarningRules'")
.AnyAsync(value => value > 0, cancellationToken);
await ApplyMigrationAsync(
AcademicWarningsMigration,
warningRulesExist ? [] : AcademicWarningStatements,
cancellationToken);
}
private async Task ApplyMigrationAsync(
@@ -1606,4 +1616,13 @@ public sealed class DevelopmentSqliteMigrator(
"""CREATE UNIQUE INDEX "IX_CourseSubstitutions_StudentId_OriginalCourseId" ON "CourseSubstitutions" ("StudentId", "OriginalCourseId");""",
"""CREATE INDEX "IX_CourseSubstitutions_Status_CreatedAt" ON "CourseSubstitutions" ("Status", "CreatedAt");"""
];
private static readonly string[] AcademicWarningStatements =
[
"""CREATE TABLE "WarningRules" ("Id" TEXT NOT NULL CONSTRAINT "PK_WarningRules" PRIMARY KEY, "Type" INTEGER NOT NULL, "Name" TEXT NOT NULL, "Threshold" TEXT NOT NULL, "IsEnabled" INTEGER NOT NULL, "NotifyStudent" INTEGER NOT NULL, "NotifyCounselor" INTEGER NOT NULL, "AcademicTermId" TEXT NOT NULL, "Description" TEXT NULL, "CreatedAt" TEXT NOT NULL, "UpdatedAt" TEXT NOT NULL, CONSTRAINT "FK_WarningRules_AcademicTerms" FOREIGN KEY ("AcademicTermId") REFERENCES "AcademicTerms" ("Id") ON DELETE CASCADE);""",
"""CREATE UNIQUE INDEX "IX_WarningRules_AcademicTermId_Type" ON "WarningRules" ("AcademicTermId", "Type");""",
"""CREATE TABLE "WarningRecords" ("Id" TEXT NOT NULL CONSTRAINT "PK_WarningRecords" PRIMARY KEY, "StudentId" TEXT NOT NULL, "Type" INTEGER NOT NULL, "Status" INTEGER NOT NULL, "TriggerValue" TEXT NOT NULL, "Detail" TEXT NOT NULL, "AcknowledgedAt" TEXT NULL, "AcknowledgeComment" TEXT NULL, "AcademicTermId" TEXT NOT NULL, "CreatedAt" TEXT NOT NULL, "UpdatedAt" TEXT NOT NULL, CONSTRAINT "FK_WarningRecords_Students" FOREIGN KEY ("StudentId") REFERENCES "Students" ("Id") ON DELETE RESTRICT);""",
"""CREATE UNIQUE INDEX "IX_WarningRecords_StudentId_AcademicTermId_Type" ON "WarningRecords" ("StudentId", "AcademicTermId", "Type");""",
"""CREATE INDEX "IX_WarningRecords_Status" ON "WarningRecords" ("Status");"""
];
}