From af68161d7a85182c095d1f83e534b7778cfd230c Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Fri, 15 Sep 2023 11:15:41 +0200 Subject: [PATCH 1/3] Refactor migrations file --- ...ctiveClientsKey.js => RenameActiveClientsKey.ts} | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) rename src/libs/migrations/{RenameActiveClientsKey.js => RenameActiveClientsKey.ts} (70%) diff --git a/src/libs/migrations/RenameActiveClientsKey.js b/src/libs/migrations/RenameActiveClientsKey.ts similarity index 70% rename from src/libs/migrations/RenameActiveClientsKey.js rename to src/libs/migrations/RenameActiveClientsKey.ts index 54b36e13cff5..cb73e64ca12c 100644 --- a/src/libs/migrations/RenameActiveClientsKey.js +++ b/src/libs/migrations/RenameActiveClientsKey.ts @@ -1,28 +1,31 @@ -import Onyx from 'react-native-onyx'; -import _ from 'underscore'; +import Onyx, {OnyxEntry} from 'react-native-onyx'; import Log from '../Log'; import ONYXKEYS from '../../ONYXKEYS'; // This migration changes the name of the Onyx key ACTIVE_CLIENTS from activeClients2 to activeClients -export default function () { +export default function (): Promise { return new Promise((resolve) => { // Connect to the old key in Onyx to get the old value of activeClients2 // then set the new key activeClients to hold the old data // finally remove the old key by setting the value to null const connectionID = Onyx.connect({ + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error key: 'activeClients2', callback: (oldActiveClients) => { Onyx.disconnect(connectionID); // Fail early here because there is nothing to migrate - if (_.isEmpty(oldActiveClients)) { + if (oldActiveClients) { Log.info('[Migrate Onyx] Skipped migration RenameActiveClientsKey'); return resolve(); } Onyx.multiSet({ + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error activeClients2: null, - [ONYXKEYS.ACTIVE_CLIENTS]: oldActiveClients, + [ONYXKEYS.ACTIVE_CLIENTS]: oldActiveClients as OnyxEntry, }).then(() => { Log.info('[Migrate Onyx] Ran migration RenameActiveClientsKey'); resolve(); From 77d56ecf68583615c899d502f7545d30baeff0d7 Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Mon, 18 Sep 2023 16:24:58 +0200 Subject: [PATCH 2/3] Remove old migration --- src/libs/migrateOnyx.js | 2 -- src/libs/migrations/RenameActiveClientsKey.ts | 36 ------------------- 2 files changed, 38 deletions(-) delete mode 100644 src/libs/migrations/RenameActiveClientsKey.ts diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index 9389a9b66fbc..f7dd7d8f2985 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -1,7 +1,6 @@ import _ from 'underscore'; import Log from './Log'; import AddEncryptedAuthToken from './migrations/AddEncryptedAuthToken'; -import RenameActiveClientsKey from './migrations/RenameActiveClientsKey'; import RenamePriorityModeKey from './migrations/RenamePriorityModeKey'; import MoveToIndexedDB from './migrations/MoveToIndexedDB'; import RenameExpensifyNewsStatus from './migrations/RenameExpensifyNewsStatus'; @@ -17,7 +16,6 @@ export default function () { // Add all migrations to an array so they are executed in order const migrationPromises = [ MoveToIndexedDB, - RenameActiveClientsKey, RenamePriorityModeKey, AddEncryptedAuthToken, RenameExpensifyNewsStatus, diff --git a/src/libs/migrations/RenameActiveClientsKey.ts b/src/libs/migrations/RenameActiveClientsKey.ts deleted file mode 100644 index cb73e64ca12c..000000000000 --- a/src/libs/migrations/RenameActiveClientsKey.ts +++ /dev/null @@ -1,36 +0,0 @@ -import Onyx, {OnyxEntry} from 'react-native-onyx'; -import Log from '../Log'; -import ONYXKEYS from '../../ONYXKEYS'; - -// This migration changes the name of the Onyx key ACTIVE_CLIENTS from activeClients2 to activeClients -export default function (): Promise { - return new Promise((resolve) => { - // Connect to the old key in Onyx to get the old value of activeClients2 - // then set the new key activeClients to hold the old data - // finally remove the old key by setting the value to null - const connectionID = Onyx.connect({ - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error - key: 'activeClients2', - callback: (oldActiveClients) => { - Onyx.disconnect(connectionID); - - // Fail early here because there is nothing to migrate - if (oldActiveClients) { - Log.info('[Migrate Onyx] Skipped migration RenameActiveClientsKey'); - return resolve(); - } - - Onyx.multiSet({ - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error - activeClients2: null, - [ONYXKEYS.ACTIVE_CLIENTS]: oldActiveClients as OnyxEntry, - }).then(() => { - Log.info('[Migrate Onyx] Ran migration RenameActiveClientsKey'); - resolve(); - }); - }, - }); - }); -} From 2a64eb3ad5439607cf4dac29b713a3aec32bd9a6 Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Wed, 20 Sep 2023 14:13:01 +0200 Subject: [PATCH 3/3] Prettier --- src/libs/migrateOnyx.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index 6cf55f908873..5b4b05598165 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -13,14 +13,7 @@ export default function () { return new Promise((resolve) => { // Add all migrations to an array so they are executed in order - const migrationPromises = [ - MoveToIndexedDB, - RenamePriorityModeKey, - AddEncryptedAuthToken, - RenameExpensifyNewsStatus, - AddLastVisibleActionCreated, - PersonalDetailsByAccountID, - ]; + const migrationPromises = [MoveToIndexedDB, RenamePriorityModeKey, AddEncryptedAuthToken, RenameExpensifyNewsStatus, AddLastVisibleActionCreated, PersonalDetailsByAccountID]; // Reduce all promises down to a single promise. All promises run in a linear fashion, waiting for the // previous promise to finish before moving onto the next one.