Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3558964
D12015.id40118.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D12015.id40118.diff
View Options
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
@@ -247,57 +247,75 @@
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,
+ );
+ };
+}
+
+async function runMigrations(
+ legacyMigrations: LegacyMigrationManifest,
+ migrations: MigrationManifest,
+ state: PersistedState,
+ inboundVersion: number,
+ currentVersion: number,
+ debug: boolean,
+): Promise<PersistedState> {
+ 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: PersistedState = 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: PersistedState = 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}`,
- },
- };
- const dbOps = {
- ...ops,
- syncedMetadataStoreOperations: [
- ...(ops.syncedMetadataStoreOperations ?? []),
- versionUpdateOp,
- ],
- };
- await getConfig().sqliteAPI.processDBStoreOperations(dbOps);
- }
+ 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}`,
+ },
+ };
+ const dbOps = {
+ ...ops,
+ syncedMetadataStoreOperations: [
+ ...(ops.syncedMetadataStoreOperations ?? []),
+ versionUpdateOp,
+ ],
+ };
+ await getConfig().sqliteAPI.processDBStoreOperations(dbOps);
}
+ }
- return migratedState;
- };
+ return migratedState;
}
export {
@@ -311,4 +329,5 @@
convertNotificationMessageInfoToNewIDSchema,
permissionsToRemoveInMigration,
createAsyncMigrate,
+ runMigrations,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 28, 5:24 AM (8 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2723890
Default Alt Text
D12015.id40118.diff (3 KB)
Attached To
Mode
D12015: [lib] Extract a function that runs the migrations
Attached
Detach File
Event Timeline
Log In to Comment