This commit is contained in:
2026-07-27 08:59:02 +08:00 Unverified
parent 22321abe23
commit 2f5c6af37c
12 changed files with 6281 additions and 212 deletions
@@ -60,6 +60,8 @@ public sealed class DevelopmentSqliteMigrator(
"20260726_32_classroom_reservations";
private const string BackgroundJobOutboxMigration =
"20260726_33_background_job_outbox";
private const string CourseAdjustmentOccurrencesMigration =
"20260727_34_course_adjustment_occurrences";
public async Task MigrateAsync(CancellationToken cancellationToken = default)
{
@@ -278,6 +280,21 @@ public sealed class DevelopmentSqliteMigrator(
courseAdjustmentsExist ? [] : CourseAdjustmentsStatements,
cancellationToken);
var courseAdjustmentOccurrencesExist = await db.Database
.SqlQueryRaw<int>(
"""
SELECT COUNT(*) AS "Value"
FROM pragma_table_info('CourseAdjustments')
WHERE name = 'SourceScheduleEntryId'
""")
.AnyAsync(value => value > 0, cancellationToken);
await ApplyMigrationAsync(
CourseAdjustmentOccurrencesMigration,
courseAdjustmentOccurrencesExist
? []
: CourseAdjustmentOccurrencesStatements,
cancellationToken);
var attendanceAppealExists = await db.Database
.SqlQueryRaw<int>(
"""
@@ -1772,6 +1789,12 @@ public sealed class DevelopmentSqliteMigrator(
"Type" INTEGER NOT NULL,
"Status" INTEGER NOT NULL,
"ApplicantUserId" TEXT NOT NULL,
"SourceScheduleEntryId" TEXT NULL,
"SourceWeek" INTEGER NULL,
"SourceDate" TEXT NULL,
"SourceStartPeriod" INTEGER NULL,
"SourcePeriodCount" INTEGER NULL,
"SourceClassroomId" TEXT NULL,
"TargetDate" TEXT NULL,
"DayOfWeek" INTEGER NULL,
"StartPeriod" INTEGER NULL,
@@ -1817,6 +1840,17 @@ public sealed class DevelopmentSqliteMigrator(
"""CREATE INDEX "IX_Notifications_CreatedAt" ON "Notifications" ("CreatedAt");"""
];
private static readonly string[] CourseAdjustmentOccurrencesStatements =
[
"""ALTER TABLE "CourseAdjustments" ADD "SourceScheduleEntryId" TEXT NULL;""",
"""ALTER TABLE "CourseAdjustments" ADD "SourceWeek" INTEGER NULL;""",
"""ALTER TABLE "CourseAdjustments" ADD "SourceDate" TEXT NULL;""",
"""ALTER TABLE "CourseAdjustments" ADD "SourceStartPeriod" INTEGER NULL;""",
"""ALTER TABLE "CourseAdjustments" ADD "SourcePeriodCount" INTEGER NULL;""",
"""ALTER TABLE "CourseAdjustments" ADD "SourceClassroomId" TEXT NULL;""",
"""CREATE INDEX "IX_CourseAdjustments_SourceScheduleEntryId_SourceWeek" ON "CourseAdjustments" ("SourceScheduleEntryId", "SourceWeek");"""
];
private static readonly string[] AttendanceAppealStatements =
[
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealStatus" INTEGER NOT NULL DEFAULT 0;""",