refactor(rooms): remove dorm gender restrictions
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getDataSourceToken } from '@nestjs/typeorm';
|
||||
import { DatabaseMigrationsService } from './database-migrations.service';
|
||||
|
||||
describe('DatabaseMigrationsService — room gender cleanup', () => {
|
||||
it('drops the retired rooms.gender column', async () => {
|
||||
const runner = {
|
||||
connect: jest.fn(),
|
||||
release: jest.fn(),
|
||||
getTables: jest.fn().mockResolvedValue([{ name: 'rooms' }]),
|
||||
getTable: jest.fn().mockResolvedValue({
|
||||
name: 'rooms',
|
||||
columns: [{ name: 'id' }, { name: 'gender' }],
|
||||
}),
|
||||
dropColumn: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
DatabaseMigrationsService,
|
||||
{
|
||||
provide: getDataSourceToken(),
|
||||
useValue: {
|
||||
options: { type: 'better-sqlite3' },
|
||||
createQueryRunner: jest.fn().mockReturnValue(runner),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
const service = module.get(DatabaseMigrationsService) as DatabaseMigrationsService & {
|
||||
removeUnusedRoomColumns(): Promise<void>;
|
||||
};
|
||||
|
||||
await service.removeUnusedRoomColumns();
|
||||
|
||||
expect(runner.dropColumn).toHaveBeenCalledWith('rooms', 'gender');
|
||||
expect(runner.release).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,7 @@ export class DatabaseMigrationsService implements OnApplicationBootstrap {
|
||||
await this.normalizeClassDates();
|
||||
await this.protectAttendanceHistory();
|
||||
await this.removeUnusedClassroomColumns();
|
||||
await this.removeUnusedRoomColumns();
|
||||
await this.cleanupDepositRefundColumns();
|
||||
await this.removeUnusedClassStudentColumns();
|
||||
await this.normalizeClassroomStatuses();
|
||||
@@ -39,6 +40,22 @@ export class DatabaseMigrationsService implements OnApplicationBootstrap {
|
||||
}
|
||||
}
|
||||
|
||||
private async removeUnusedRoomColumns(): Promise<void> {
|
||||
const runner = this.dataSource.createQueryRunner();
|
||||
await runner.connect();
|
||||
try {
|
||||
const tables = await runner.getTables(['rooms']);
|
||||
if (tables.length === 0) return;
|
||||
|
||||
const table = await runner.getTable('rooms');
|
||||
if (table?.columns.some((column) => column.name === 'gender')) {
|
||||
await runner.dropColumn('rooms', 'gender');
|
||||
}
|
||||
} finally {
|
||||
await runner.release();
|
||||
}
|
||||
}
|
||||
|
||||
private async cleanupDepositRefundColumns(): Promise<void> {
|
||||
const runner = this.dataSource.createQueryRunner();
|
||||
await runner.connect();
|
||||
|
||||
Reference in New Issue
Block a user