教学点名强化
This commit is contained in:
@@ -543,6 +543,9 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
{
|
||||
entity.HasKey(x => new { x.AttendanceSheetId, x.StudentId });
|
||||
entity.Property(x => x.Notes).HasMaxLength(300);
|
||||
entity.Property(x => x.AppealReason).HasMaxLength(500);
|
||||
entity.Property(x => x.AppealReviewComment).HasMaxLength(300);
|
||||
entity.HasIndex(x => x.AppealStatus);
|
||||
entity.HasOne(x => x.AttendanceSheet)
|
||||
.WithMany(x => x.Records)
|
||||
.HasForeignKey(x => x.AttendanceSheetId)
|
||||
|
||||
@@ -38,6 +38,8 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
"20260725_21_retake_enrollment";
|
||||
private const string CourseAdjustmentsMigration =
|
||||
"20260725_22_course_adjustments";
|
||||
private const string AttendanceAppealMigration =
|
||||
"20260725_23_attendance_appeal";
|
||||
|
||||
public async Task MigrateAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -255,6 +257,19 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
CourseAdjustmentsMigration,
|
||||
courseAdjustmentsExist ? [] : CourseAdjustmentsStatements,
|
||||
cancellationToken);
|
||||
|
||||
var attendanceAppealExists = await db.Database
|
||||
.SqlQueryRaw<int>(
|
||||
"""
|
||||
SELECT COUNT(*) AS "Value"
|
||||
FROM pragma_table_info('AttendanceRecords')
|
||||
WHERE name = 'AppealStatus'
|
||||
""")
|
||||
.AnyAsync(value => value > 0, cancellationToken);
|
||||
await ApplyMigrationAsync(
|
||||
AttendanceAppealMigration,
|
||||
attendanceAppealExists ? [] : AttendanceAppealStatements,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private async Task ApplyMigrationAsync(
|
||||
@@ -1553,4 +1568,14 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
"""CREATE INDEX "IX_Notifications_UserId_IsRead" ON "Notifications" ("UserId", "IsRead");""",
|
||||
"""CREATE INDEX "IX_Notifications_CreatedAt" ON "Notifications" ("CreatedAt");"""
|
||||
];
|
||||
|
||||
private static readonly string[] AttendanceAppealStatements =
|
||||
[
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealStatus" INTEGER NOT NULL DEFAULT 0;""",
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealReason" TEXT NULL;""",
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealSubmittedAt" TEXT NULL;""",
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealReviewComment" TEXT NULL;""",
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealReviewedAt" TEXT NULL;""",
|
||||
"""CREATE INDEX IF NOT EXISTS "IX_AttendanceRecords_AppealStatus" ON "AttendanceRecords" ("AppealStatus");"""
|
||||
];
|
||||
}
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AttendanceAppeal : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "AppealStatus",
|
||||
table: "AttendanceRecords",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "AppealReason",
|
||||
table: "AttendanceRecords",
|
||||
type: "varchar(500)",
|
||||
maxLength: 500,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "AppealSubmittedAt",
|
||||
table: "AttendanceRecords",
|
||||
type: "datetime(6)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "AppealReviewComment",
|
||||
table: "AttendanceRecords",
|
||||
type: "varchar(300)",
|
||||
maxLength: 300,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "AppealReviewedAt",
|
||||
table: "AttendanceRecords",
|
||||
type: "datetime(6)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AttendanceRecords_AppealStatus",
|
||||
table: "AttendanceRecords",
|
||||
column: "AppealStatus");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_AttendanceRecords_AppealStatus",
|
||||
table: "AttendanceRecords");
|
||||
|
||||
migrationBuilder.DropColumn(name: "AppealReviewedAt", table: "AttendanceRecords");
|
||||
migrationBuilder.DropColumn(name: "AppealReviewComment", table: "AttendanceRecords");
|
||||
migrationBuilder.DropColumn(name: "AppealSubmittedAt", table: "AttendanceRecords");
|
||||
migrationBuilder.DropColumn(name: "AppealReason", table: "AttendanceRecords");
|
||||
migrationBuilder.DropColumn(name: "AppealStatus", table: "AttendanceRecords");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user