From a2979a601f00985a50a76ea8d926ccd59af7ed35 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Mon, 16 Mar 2026 22:01:31 +0530 Subject: [PATCH] Removed ConvertPolicyChatReportIDsToString migration --- src/libs/migrateOnyx.ts | 3 +- src/libs/migrations/.keep | 0 .../ConvertPolicyChatReportIDsToString.ts | 93 ------------------- 3 files changed, 1 insertion(+), 95 deletions(-) create mode 100644 src/libs/migrations/.keep delete mode 100644 src/libs/migrations/ConvertPolicyChatReportIDsToString.ts diff --git a/src/libs/migrateOnyx.ts b/src/libs/migrateOnyx.ts index d8e1a90f66819..f5c5d253a1ca3 100644 --- a/src/libs/migrateOnyx.ts +++ b/src/libs/migrateOnyx.ts @@ -1,6 +1,5 @@ import CONST from '@src/CONST'; import Log from './Log'; -import ConvertPolicyChatReportIDsToString from './migrations/ConvertPolicyChatReportIDsToString'; import {endSpan, getSpan, startSpan} from './telemetry/activeSpans'; export default function () { @@ -15,7 +14,7 @@ export default function () { }); // Add all migrations to an array so they are executed in order - const migrationPromises = [ConvertPolicyChatReportIDsToString]; + const migrationPromises: Array<() => Promise> = []; // 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. diff --git a/src/libs/migrations/.keep b/src/libs/migrations/.keep new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/libs/migrations/ConvertPolicyChatReportIDsToString.ts b/src/libs/migrations/ConvertPolicyChatReportIDsToString.ts deleted file mode 100644 index 9c8852f020f12..0000000000000 --- a/src/libs/migrations/ConvertPolicyChatReportIDsToString.ts +++ /dev/null @@ -1,93 +0,0 @@ -import Onyx from 'react-native-onyx'; -import type {OnyxCollection} from 'react-native-onyx'; -import Log from '@libs/Log'; -import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy} from '@src/types/onyx'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; - -type PolicyKey = `${typeof ONYXKEYS.COLLECTION.POLICY}${string}`; - -type OldPolicy = Policy & { - chatReportIDAdmins?: string | number; - chatReportIDAnnounce?: string | number; -}; - -type PolicyUpdate = { - chatReportIDAdmins?: string; - chatReportIDAnnounce?: string; -}; - -/** - * This migration converts chatReportIDAdmins and chatReportIDAnnounce from number to string - * to match the expected string type for report IDs. - */ -export default function () { - return new Promise((resolve) => { - const connection = Onyx.connectWithoutView({ - key: ONYXKEYS.COLLECTION.POLICY, - waitForCollectionCallback: true, - callback: (policies: OnyxCollection) => { - Onyx.disconnect(connection); - - if (!policies || isEmptyObject(policies)) { - Log.info('[Migrate Onyx] Skipped migration ConvertPolicyChatReportIDsToString because there are no policies'); - return resolve(); - } - - // Find policies that have number type chatReportIDAdmins or chatReportIDAnnounce - const policiesToMigrate = Object.entries(policies).filter(([, policy]) => { - if (!policy) { - return false; - } - - const hasNumberAdminsReportID = typeof policy.chatReportIDAdmins === 'number'; - const hasNumberAnnounceReportID = typeof policy.chatReportIDAnnounce === 'number'; - - return hasNumberAdminsReportID || hasNumberAnnounceReportID; - }); - - if (policiesToMigrate.length === 0) { - Log.info('[Migrate Onyx] Skipped migration ConvertPolicyChatReportIDsToString because no policies have number type chatReportIDs'); - return resolve(); - } - - Log.info(`[Migrate Onyx] Running ConvertPolicyChatReportIDsToString migration for ${policiesToMigrate.length} policies`); - - const dataToSave = policiesToMigrate.reduce( - (acc, [policyKey, policy]) => { - if (!policy) { - return acc; - } - - const update: PolicyUpdate = {}; - - if (typeof policy.chatReportIDAdmins === 'number') { - update.chatReportIDAdmins = String(policy.chatReportIDAdmins); - Log.info( - `[Migrate Onyx] ConvertPolicyChatReportIDsToString: Converting chatReportIDAdmins from ${policy.chatReportIDAdmins} to "${update.chatReportIDAdmins}" for policy ${policyKey}`, - ); - } - - if (typeof policy.chatReportIDAnnounce === 'number') { - update.chatReportIDAnnounce = String(policy.chatReportIDAnnounce); - Log.info( - `[Migrate Onyx] ConvertPolicyChatReportIDsToString: Converting chatReportIDAnnounce from ${policy.chatReportIDAnnounce} to "${update.chatReportIDAnnounce}" for policy ${policyKey}`, - ); - } - - acc[policyKey as PolicyKey] = update; - - return acc; - }, - {} as Record, - ); - - // eslint-disable-next-line rulesdir/prefer-actions-set-data - Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, dataToSave).then(() => { - Log.info(`[Migrate Onyx] Ran migration ConvertPolicyChatReportIDsToString and converted ${Object.keys(dataToSave).length} policies`); - resolve(); - }); - }, - }); - }); -}