From 3809ba2027e92cb9afcb886458ae6188c8132c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Mon, 18 Sep 2023 20:46:41 +0200 Subject: [PATCH] delete KeyReportActionsByReportActionID.js --- src/libs/migrateOnyx.js | 2 - .../KeyReportActionsByReportActionID.js | 64 ----------- tests/unit/MigrationTest.js | 107 ------------------ 3 files changed, 173 deletions(-) delete mode 100644 src/libs/migrations/KeyReportActionsByReportActionID.js diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index 9389a9b66fbc..e691ea22ba79 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -6,7 +6,6 @@ import RenamePriorityModeKey from './migrations/RenamePriorityModeKey'; import MoveToIndexedDB from './migrations/MoveToIndexedDB'; import RenameExpensifyNewsStatus from './migrations/RenameExpensifyNewsStatus'; import AddLastVisibleActionCreated from './migrations/AddLastVisibleActionCreated'; -import KeyReportActionsByReportActionID from './migrations/KeyReportActionsByReportActionID'; import PersonalDetailsByAccountID from './migrations/PersonalDetailsByAccountID'; export default function () { @@ -22,7 +21,6 @@ export default function () { AddEncryptedAuthToken, RenameExpensifyNewsStatus, AddLastVisibleActionCreated, - KeyReportActionsByReportActionID, PersonalDetailsByAccountID, ]; diff --git a/src/libs/migrations/KeyReportActionsByReportActionID.js b/src/libs/migrations/KeyReportActionsByReportActionID.js deleted file mode 100644 index 0dc1d003feab..000000000000 --- a/src/libs/migrations/KeyReportActionsByReportActionID.js +++ /dev/null @@ -1,64 +0,0 @@ -import _ from 'underscore'; -import Onyx from 'react-native-onyx'; -import Log from '../Log'; -import ONYXKEYS from '../../ONYXKEYS'; - -/** - * This migration updates reportActions data to be keyed by reportActionID rather than by sequenceNumber. - * - * @returns {Promise} - */ -export default function () { - return new Promise((resolve) => { - const connectionID = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, - waitForCollectionCallback: true, - callback: (allReportActions) => { - Onyx.disconnect(connectionID); - - if (!allReportActions) { - Log.info('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because there were no reportActions'); - return resolve(); - } - - const newReportActions = {}; - const allReportActionsEntires = Object.entries(allReportActions); - for (let i = 0; i < allReportActionsEntires.length; i++) { - const [onyxKey, reportActionsForReport] = allReportActionsEntires[i]; - if (reportActionsForReport) { - const newReportActionsForReport = {}; - const reportActionsForReportEntries = Object.entries(reportActionsForReport); - for (let j = 0; j < reportActionsForReportEntries.length; j++) { - const [reportActionKey, reportAction] = reportActionsForReportEntries[j]; - if (!reportAction) { - Log.info('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because the reportAction was deleted'); - return resolve(); - } - if ( - !_.isNaN(Number(reportActionKey)) && - Number(reportActionKey) === Number(reportAction.reportActionID) && - Number(reportActionKey) !== Number(reportAction.sequenceNumber) - ) { - Log.info('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because we already migrated it'); - return resolve(); - } - - // Move it to be keyed by reportActionID instead - newReportActionsForReport[reportAction.reportActionID] = reportAction; - } - newReportActions[onyxKey] = newReportActionsForReport; - } - } - - if (_.isEmpty(newReportActions)) { - Log.info('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because there are no actions to migrate'); - return resolve(); - } - - Log.info(`[Migrate Onyx] Re-keying reportActions by reportActionID for ${_.keys(newReportActions).length} reports`); - // eslint-disable-next-line rulesdir/prefer-actions-set-data - return Onyx.multiSet(newReportActions).then(resolve); - }, - }); - }); -} diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index 0171ee640226..c33d851f49fa 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -6,7 +6,6 @@ import Log from '../../src/libs/Log'; import getPlatform from '../../src/libs/getPlatform'; import AddLastVisibleActionCreated from '../../src/libs/migrations/AddLastVisibleActionCreated'; import MoveToIndexedDB from '../../src/libs/migrations/MoveToIndexedDB'; -import KeyReportActionsByReportActionID from '../../src/libs/migrations/KeyReportActionsByReportActionID'; import PersonalDetailsByAccountID from '../../src/libs/migrations/PersonalDetailsByAccountID'; import CheckForPreviousReportActionID from '../../src/libs/migrations/CheckForPreviousReportActionID'; import ONYXKEYS from '../../src/ONYXKEYS'; @@ -150,112 +149,6 @@ describe('Migrations', () => { })); }); - describe('KeyReportActionsByReportActionID', () => { - // Warning: this test has to come before the others in this suite because Onyx.clear leaves traces and keys with null values aren't cleared out between tests - it("Should work even if there's no reportAction data in Onyx", () => - KeyReportActionsByReportActionID().then(() => - expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because there were no reportActions'), - )); - - it("Should work even if there's zombie reportAction data in Onyx", () => - Onyx.multiSet({ - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: null, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]: null, - }) - .then(KeyReportActionsByReportActionID) - .then(() => { - expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because there are no actions to migrate'); - const connectionID = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, - waitForCollectionCallback: true, - callback: (allReportActions) => { - Onyx.disconnect(connectionID); - _.each(allReportActions, (reportActionsForReport) => expect(reportActionsForReport).toBeNull()); - }, - }); - })); - - it('Should migrate reportActions to be keyed by reportActionID instead of sequenceNumber', () => - Onyx.multiSet({ - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { - 1: { - reportActionID: '1000', - sequenceNumber: 1, - }, - 2: { - reportActionID: '2000', - sequenceNumber: 2, - }, - }, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]: { - 1: { - reportActionID: '3000', - sequenceNumber: 1, - }, - 2: { - reportActionID: '4000', - sequenceNumber: 2, - }, - }, - }) - .then(KeyReportActionsByReportActionID) - .then(() => { - expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Re-keying reportActions by reportActionID for 2 reports'); - const connectionID = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, - waitForCollectionCallback: true, - callback: (allReportActions) => { - Onyx.disconnect(connectionID); - expect(_.keys(allReportActions).length).toBe(2); - _.each(allReportActions, (reportActionsForReport) => { - _.each(reportActionsForReport, (reportAction, key) => { - expect(key).toBe(reportAction.reportActionID); - }); - }); - }, - }); - })); - - it('Should return early if the migration has already happened', () => - Onyx.multiSet({ - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { - 1000: { - reportActionID: '1000', - sequenceNumber: 1, - }, - 2000: { - reportActionID: '2000', - sequenceNumber: 2, - }, - }, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]: { - 3000: { - reportActionID: '3000', - }, - 4000: { - reportActionID: '4000', - }, - }, - }) - .then(KeyReportActionsByReportActionID) - .then(() => { - expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because we already migrated it'); - const connectionID = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, - waitForCollectionCallback: true, - callback: (allReportActions) => { - Onyx.disconnect(connectionID); - expect(_.keys(allReportActions).length).toBe(2); - _.each(allReportActions, (reportActionsForReport) => { - _.each(reportActionsForReport, (reportAction, key) => { - expect(key).toBe(reportAction.reportActionID); - }); - }); - }, - }); - })); - }); - describe('PersonalDetailsByAccountID', () => { const DEPRECATED_ONYX_KEYS = { // Deprecated personal details object which was keyed by login instead of accountID.