1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00
Files
browser/libs/common/src/platform/services/migration-runner.ts
Justin Baur 3caa6cb635 [PM-7766] Add clientType to MigrationHelper (#8945)
* Add `clientType` to MigrationHelper

* PM-7766 - Fix migration builder tests to take new clientType into account.

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>

* PM-7766 - Add client type to migration builder tests.

* PM-7766 - Fix migration-helper.spec tests.

* PM-7766 - Fix migrator.spec.ts

---------

Co-authored-by: Jared Snider <jsnider@bitwarden.com>
2024-04-29 07:28:58 -04:00

42 lines
1.4 KiB
TypeScript

import { ClientType } from "../../enums";
import { waitForMigrations } from "../../state-migrations";
import { CURRENT_VERSION, currentVersion } from "../../state-migrations/migrate";
import { MigrationHelper } from "../../state-migrations/migration-helper";
import { LogService } from "../abstractions/log.service";
import { AbstractStorageService } from "../abstractions/storage.service";
import { MigrationBuilderService } from "./migration-builder.service";
export class MigrationRunner {
constructor(
protected diskStorage: AbstractStorageService,
protected logService: LogService,
protected migrationBuilderService: MigrationBuilderService,
private clientType: ClientType,
) {}
async run(): Promise<void> {
const migrationHelper = new MigrationHelper(
await currentVersion(this.diskStorage, this.logService),
this.diskStorage,
this.logService,
"general",
this.clientType,
);
if (migrationHelper.currentVersion < 0) {
// Cannot determine state, assuming empty so we don't repeatedly apply a migration.
await this.diskStorage.save("stateVersion", CURRENT_VERSION);
return;
}
const migrationBuilder = this.migrationBuilderService.build();
await migrationBuilder.migrate(migrationHelper);
}
async waitForCompletion(): Promise<void> {
await waitForMigrations(this.diskStorage, this.logService);
}
}