fix: harden DingTalk student synchronization

This commit is contained in:
2026-07-18 14:51:53 +08:00
parent d25e451b61
commit c11f6bb614
15 changed files with 758 additions and 356 deletions

View File

@@ -10,6 +10,7 @@ export class DatabaseMigrationsService implements OnApplicationBootstrap {
async onApplicationBootstrap(): Promise<void> {
await this.ensureAiConfigTable();
await this.ensureSyncStateLeaseColumns();
await this.ensureCourseAttendanceSchema();
await this.ensureAttendanceDevicesSchema();
await this.ensureStudentWalletSchema();
@@ -23,6 +24,24 @@ export class DatabaseMigrationsService implements OnApplicationBootstrap {
await this.normalizeClassroomStatuses();
}
private async ensureSyncStateLeaseColumns(): Promise<void> {
const runner = this.dataSource.createQueryRunner();
await runner.connect();
try {
const table = await runner.getTable('sync_state');
if (!table) return;
const columns = new Set(table.columns.map((column) => column.name));
if (!columns.has('run_id')) {
await runner.query('ALTER TABLE sync_state ADD COLUMN run_id VARCHAR(64)');
}
if (!columns.has('running_since')) {
await runner.query('ALTER TABLE sync_state ADD COLUMN running_since DATETIME');
}
} finally {
await runner.release();
}
}
private async ensureAttendanceDevicesSchema(): Promise<void> {
const runner = this.dataSource.createQueryRunner();
await runner.connect();

View File

@@ -49,6 +49,7 @@ function createDataSource(runner: MockRunner, dbType: string = 'better-sqlite3')
// Type to reach private migration methods for testing
interface MigrationsPrivate {
ensureAiConfigTable(): Promise<void>;
ensureSyncStateLeaseColumns(): Promise<void>;
backfillOrganizations(): Promise<void>;
normalizeClassDates(): Promise<void>;
ensureCourseAttendanceSchema(): Promise<void>;