fix: update getMigrations method to accept version range parameters and fix tests

This commit is contained in:
Ivan Kalashnikov 2026-01-19 01:04:29 +07:00
parent 48148a5a27
commit e8d5dff3b9
2 changed files with 19 additions and 4 deletions

View file

@ -68,7 +68,7 @@ describe('SchemaMigrationService', () => {
it('should return empty array for initial version', () => {
// No migrations defined yet for version 1
const migrations = service.getMigrations();
const migrations = service.getMigrations(1, 1);
expect(migrations.length).toBe(0);
});
});

View file

@ -224,9 +224,24 @@ export class SchemaMigrationService {
}
/**
* Returns all registered migrations (for debugging/testing).
* Returns registered migrations for a specific version range.
* If no range is provided, returns all migrations.
*
* @param fromVersion - The starting version (inclusive).
* @param toVersion - The ending version (inclusive).
* @returns Array of migrations within the specified range.
*/
getMigrations(): readonly SchemaMigration[] {
return MIGRATIONS;
getMigrations(fromVersion?: number, toVersion?: number): readonly SchemaMigration[] {
if (fromVersion === undefined && toVersion === undefined) {
return MIGRATIONS;
}
return MIGRATIONS.filter((migration) => {
const isAfterFromVersion =
fromVersion === undefined || migration.fromVersion >= fromVersion;
const isBeforeToVersion =
toVersion === undefined || migration.toVersion <= toVersion;
return isAfterFromVersion && isBeforeToVersion;
});
}
}