1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00
Files
browser/libs/state/src/state-migrations/migrations/69-migrate-incorrect-folder-key.ts
Addison Beck 361f7e3447 refactor: introduce @bitwarden/state and other common libs (#15772)
* refactor: introduce @bitwarden/serialization

* refactor: introduce @bitwarden/guid

* refactor: introduce @bitwaren/client-type

* refactor: introduce @bitwarden/core-test-utils

* refactor: introduce @bitwarden/state and @bitwarden/state-test-utils

Creates initial project structure for centralized application state management. Part of modularization effort to extract state code from common.

* Added state provider documentation to README.

* Changed callouts to Github format.

* Fixed linting on file name.

* Forced git to accept rename

---------

Co-authored-by: Todd Martin <tmartin@bitwarden.com>
2025-08-04 11:01:28 -04:00

43 lines
1.4 KiB
TypeScript

import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
import { Migrator } from "../migrator";
const BAD_FOLDER_KEY: KeyDefinitionLike = {
key: "folder", // We inadvertently changed the key from "folders" to "folder"
stateDefinition: {
name: "folder",
},
};
const GOOD_FOLDER_KEY: KeyDefinitionLike = {
key: "folders", // We should keep the key as "folders"
stateDefinition: {
name: "folder",
},
};
export class MigrateIncorrectFolderKey extends Migrator<68, 69> {
async migrate(helper: MigrationHelper): Promise<void> {
async function migrateUser(userId: string) {
const value = await helper.getFromUser(userId, BAD_FOLDER_KEY);
if (value != null) {
await helper.setToUser(userId, GOOD_FOLDER_KEY, value);
}
await helper.removeFromUser(userId, BAD_FOLDER_KEY);
}
const users = await helper.getKnownUserIds();
await Promise.all(users.map((userId) => migrateUser(userId)));
}
async rollback(helper: MigrationHelper): Promise<void> {
async function rollbackUser(userId: string) {
const value = await helper.getFromUser(userId, GOOD_FOLDER_KEY);
if (value != null) {
await helper.setToUser(userId, BAD_FOLDER_KEY, value);
}
await helper.removeFromUser(userId, GOOD_FOLDER_KEY);
}
const users = await helper.getKnownUserIds();
await Promise.all(users.map((userId) => rollbackUser(userId)));
}
}