Page MenuHomePhabricator

D12015.diff
No OneTemporary

D12015.diff

diff --git a/lib/utils/migration-utils.js b/lib/utils/migration-utils.js
--- a/lib/utils/migration-utils.js
+++ b/lib/utils/migration-utils.js
@@ -251,61 +251,81 @@
return state;
}
- const migrationKeys = [
- ...Object.keys(legacyMigrations),
- ...Object.keys(migrations),
- ]
- .map(ver => parseInt(ver))
- .filter(key => currentVersion >= key && key > inboundVersion);
- const sortedMigrationKeys = migrationKeys.sort((a, b) => a - b);
+ return await runMigrations(
+ legacyMigrations,
+ migrations,
+ state,
+ inboundVersion,
+ currentVersion,
+ debug,
+ handleException,
+ );
+ };
+}
+
+async function runMigrations<N: BaseNavInfo, T: BaseAppState<N>>(
+ legacyMigrations: LegacyMigrationManifest<N, T>,
+ migrations: MigrationManifest<N, T>,
+ state: T,
+ inboundVersion: number,
+ currentVersion: number,
+ debug: boolean,
+ handleException: (error: Error, state: T) => T,
+): Promise<PersistedState<N, T>> {
+ const migrationKeys = [
+ ...Object.keys(legacyMigrations),
+ ...Object.keys(migrations),
+ ]
+ .map(ver => parseInt(ver))
+ .filter(key => currentVersion >= key && key > inboundVersion);
+ const sortedMigrationKeys = migrationKeys.sort((a, b) => a - b);
+
+ if (debug) {
+ console.log('redux-persist: migrationKeys', sortedMigrationKeys);
+ }
+ let migratedState = state;
+ for (const versionKey of sortedMigrationKeys) {
if (debug) {
- console.log('redux-persist: migrationKeys', sortedMigrationKeys);
+ console.log(
+ 'redux-persist: running migration for versionKey',
+ versionKey,
+ );
}
- let migratedState = state;
- for (const versionKey of sortedMigrationKeys) {
- if (debug) {
- console.log(
- 'redux-persist: running migration for versionKey',
- versionKey,
- );
- }
-
- if (!versionKey) {
- continue;
- }
+ if (!versionKey) {
+ continue;
+ }
- if (legacyMigrations[versionKey]) {
- migratedState = await legacyMigrations[versionKey](migratedState);
- } else {
- const { state: newState, ops } =
- await migrations[versionKey](migratedState);
- migratedState = newState;
- const versionUpdateOp = {
- type: 'replace_synced_metadata_entry',
- payload: {
- name: syncedMetadataNames.DB_VERSION,
- data: versionKey.toString(),
- },
- };
- const dbOps = {
- ...ops,
- syncedMetadataStoreOperations: [
- ...(ops.syncedMetadataStoreOperations ?? []),
- versionUpdateOp,
- ],
- };
- try {
- await getConfig().sqliteAPI.processDBStoreOperations(dbOps);
- } catch (exception) {
- return handleException(exception, state);
- }
+ if (legacyMigrations[versionKey]) {
+ migratedState = await legacyMigrations[versionKey](migratedState);
+ } else {
+ const { state: newState, ops } =
+ await migrations[versionKey](migratedState);
+ migratedState = newState;
+ const versionUpdateOp = {
+ type: 'replace_synced_metadata_entry',
+ payload: {
+ name: syncedMetadataNames.DB_VERSION,
+ data: versionKey.toString(),
+ },
+ };
+ const dbOps = {
+ ...ops,
+ syncedMetadataStoreOperations: [
+ ...(ops.syncedMetadataStoreOperations ?? []),
+ versionUpdateOp,
+ ],
+ };
+ try {
+ await getConfig().sqliteAPI.processDBStoreOperations(dbOps);
+ } catch (exception) {
+ return handleException(exception, state);
}
}
+ }
- return migratedState;
- };
+ return migratedState;
}
export {
@@ -319,4 +339,5 @@
convertNotificationMessageInfoToNewIDSchema,
permissionsToRemoveInMigration,
createAsyncMigrate,
+ runMigrations,
};

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 27, 1:19 PM (8 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2713664
Default Alt Text
D12015.diff (3 KB)

Event Timeline