mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 00:03:56 +00:00
[PM-6032] Run migrations in main process (#7795)
* Run Migrations in Desktop Main Process * Add `waitForMigrations` method * Add `InitOptions` * Fix Destructuring
This commit is contained in:
@@ -16,6 +16,7 @@ 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";
|
||||
@@ -33,7 +34,10 @@ import { CollectionView } from "../../vault/models/view/collection.view";
|
||||
import { AddEditCipherInfo } from "../../vault/types/add-edit-cipher-info";
|
||||
import { EnvironmentService } from "../abstractions/environment.service";
|
||||
import { LogService } from "../abstractions/log.service";
|
||||
import { StateService as StateServiceAbstraction } from "../abstractions/state.service";
|
||||
import {
|
||||
InitOptions,
|
||||
StateService as StateServiceAbstraction,
|
||||
} from "../abstractions/state.service";
|
||||
import {
|
||||
AbstractMemoryStorageService,
|
||||
AbstractStorageService,
|
||||
@@ -126,12 +130,20 @@ export class StateService<
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
async init(initOptions: InitOptions = {}): Promise<void> {
|
||||
// Deconstruct and apply defaults
|
||||
const { runMigrations = true } = initOptions;
|
||||
if (this.hasBeenInited) {
|
||||
return;
|
||||
}
|
||||
|
||||
await migrate(this.storageService, this.logService);
|
||||
if (runMigrations) {
|
||||
await migrate(this.storageService, this.logService);
|
||||
} 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.state().then(async (state) => {
|
||||
if (state == null) {
|
||||
|
||||
Reference in New Issue
Block a user