refactor(deposits): remove refund approval remnants

This commit is contained in:
2026-07-13 14:19:58 +08:00
parent 7b08560aef
commit 1f32d1285b
7 changed files with 186 additions and 40 deletions

View File

@@ -15,6 +15,7 @@ export class DatabaseMigrationsService implements OnApplicationBootstrap {
await this.normalizeClassDates();
await this.protectAttendanceHistory();
await this.removeUnusedClassroomColumns();
await this.cleanupDepositRefundColumns();
}
private async removeUnusedClassroomColumns(): Promise<void> {
@@ -36,6 +37,44 @@ export class DatabaseMigrationsService implements OnApplicationBootstrap {
}
}
private async cleanupDepositRefundColumns(): Promise<void> {
const runner = this.dataSource.createQueryRunner();
await runner.connect();
try {
const tables = await runner.getTables(['deposits']);
if (tables.length === 0) return;
const table = await runner.getTable('deposits');
const columnNames = new Set(table?.columns.map((column) => column.name) ?? []);
for (const [legacyName, currentName] of [
['refund_approved_by', 'refunded_by'],
['refund_approved_at', 'refunded_at'],
] as const) {
if (!columnNames.has(legacyName)) continue;
if (columnNames.has(currentName)) {
await runner.query(
`UPDATE deposits SET ${currentName} = COALESCE(${currentName}, ${legacyName})`,
);
await runner.dropColumn('deposits', legacyName);
} else {
await runner.renameColumn('deposits', legacyName, currentName);
columnNames.add(currentName);
}
columnNames.delete(legacyName);
}
for (const columnName of ['refund_status', 'refund_requested_at', 'refund_rejected_reason']) {
if (columnNames.has(columnName)) {
await runner.dropColumn('deposits', columnName);
columnNames.delete(columnName);
}
}
} finally {
await runner.release();
}
}
private async ensureAiConfigTable(): Promise<void> {
const runner = this.dataSource.createQueryRunner();
await runner.connect();