mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
fix: update getMigrations method to accept version range parameters and fix tests
This commit is contained in:
parent
48148a5a27
commit
e8d5dff3b9
2 changed files with 19 additions and 4 deletions
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue