mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
[PM-6172] Run localStorage migrations for web (#7900)
* Create MigrationRunner - Create MigrationRunner Service for running migrations in StateService - Create web override so that migrations also run against `localStorage` * Fix Web StateService * Fix WebMigrationRunner * Fix CLI * Fix ElectronStateService * Update Comment * More Common Scenarios
This commit is contained in:
@@ -14,8 +14,6 @@ import { BiometricKey } from "../../auth/types/biometric-key";
|
||||
import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum";
|
||||
import { EventData } from "../../models/data/event.data";
|
||||
import { WindowState } from "../../models/domain/window-state";
|
||||
import { migrate } from "../../state-migrations";
|
||||
import { waitForMigrations } from "../../state-migrations/migrate";
|
||||
import { GeneratorOptions } from "../../tools/generator/generator-options";
|
||||
import { GeneratedPasswordHistory, PasswordGeneratorOptions } from "../../tools/generator/password";
|
||||
import { UsernameGeneratorOptions } from "../../tools/generator/username";
|
||||
@@ -57,6 +55,8 @@ import { State } from "../models/domain/state";
|
||||
import { StorageOptions } from "../models/domain/storage-options";
|
||||
import { SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key";
|
||||
|
||||
import { MigrationRunner } from "./migration-runner";
|
||||
|
||||
const keys = {
|
||||
state: "state",
|
||||
stateVersion: "stateVersion",
|
||||
@@ -108,6 +108,7 @@ export class StateService<
|
||||
protected stateFactory: StateFactory<TGlobalState, TAccount>,
|
||||
protected accountService: AccountService,
|
||||
protected environmentService: EnvironmentService,
|
||||
private migrationRunner: MigrationRunner,
|
||||
protected useAccountCache: boolean = true,
|
||||
) {
|
||||
// If the account gets changed, verify the new account is unlocked
|
||||
@@ -136,11 +137,11 @@ export class StateService<
|
||||
}
|
||||
|
||||
if (runMigrations) {
|
||||
await migrate(this.storageService, this.logService);
|
||||
await this.migrationRunner.run();
|
||||
} else {
|
||||
// It may have been requested to not run the migrations but we should defensively not
|
||||
// continue this method until migrations have a chance to be completed elsewhere.
|
||||
await waitForMigrations(this.storageService, this.logService);
|
||||
await this.migrationRunner.waitForCompletion();
|
||||
}
|
||||
|
||||
await this.state().then(async (state) => {
|
||||
|
||||
Reference in New Issue
Block a user