From b7015c1dfab8f457f869fbdfa856d1e85da102dd Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 17 Nov 2025 18:43:54 +0000 Subject: [PATCH] Merge pull request #29717 from overleaf/ii-subscpriptions-v1-id-index-history-v1 [web] Fix failing acceptance tests in history-v1 and github-sync GitOrigin-RevId: cae820598dfe7779386958fd759d3381b6007303 --- ...110238_update_subscription_v1_id_index.mjs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/migrations/20251030110238_update_subscription_v1_id_index.mjs b/tools/migrations/20251030110238_update_subscription_v1_id_index.mjs index e29c28d289..0c38539ddd 100644 --- a/tools/migrations/20251030110238_update_subscription_v1_id_index.mjs +++ b/tools/migrations/20251030110238_update_subscription_v1_id_index.mjs @@ -17,6 +17,13 @@ const newIndexes = [ sparse: true, }, ] +const tempIndex = [ + { + key: { v1_id: 1 }, + name: 'v1_id_temp_migration', + sparse: false, // Non-sparse so it includes null/missing values + }, +] async function removeNullV1Ids(collection) { // Remove the v1_id field from documents where it's null @@ -64,14 +71,21 @@ async function assertNoDuplicateV1Ids(collection) { const migrate = async client => { const { db } = client + // Create temporary non-sparse index to allow queries with notablescan enabled + await Helpers.addIndexesToCollection(db.subscriptions, tempIndex) + // pre‑check (keep old index intact if failing) - await assertNoDuplicateV1Ids(db.subscriptions) - await removeNullV1Ids(db.subscriptions) + try { + await assertNoDuplicateV1Ids(db.subscriptions) + await removeNullV1Ids(db.subscriptions) + } catch (error) { + await Helpers.dropIndexesFromCollection(tempIndex) + throw error + } await Helpers.addIndexesToCollection(db.subscriptions, newIndexes) await Helpers.dropIndexesFromCollection( db.subscriptions, - // drop the 20251010082205 index too which wasn't working properly - originalIndexes.concat({ name: 'v1_id_2' }) + originalIndexes.concat({ name: 'v1_id_2' }).concat(tempIndex) ) }