From 49df2bd987c53a08a860cc1c941c8b43807581c0 Mon Sep 17 00:00:00 2001 From: Pierre Lehnen Date: Fri, 13 May 2022 15:38:55 -0300 Subject: [PATCH] [Chore] Reorder unreleased migrations --- apps/meteor/server/startup/migrations/v262.ts | 43 ++++--------------- apps/meteor/server/startup/migrations/v264.ts | 43 +++++++++++++++---- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/apps/meteor/server/startup/migrations/v262.ts b/apps/meteor/server/startup/migrations/v262.ts index a42b574bf3dd..47496885909d 100644 --- a/apps/meteor/server/startup/migrations/v262.ts +++ b/apps/meteor/server/startup/migrations/v262.ts @@ -1,41 +1,16 @@ -import { MongoInternals } from 'meteor/mongo'; - import { addMigration } from '../../lib/migrations'; +import { Settings } from '../../../app/models/server/raw'; addMigration({ version: 262, async up() { - const { mongo } = MongoInternals.defaultRemoteCollectionDriver(); - const npsVote = mongo.db.collection('rocketchat_nps_vote'); - - const duplicated = await npsVote - .aggregate([ - { - $group: { - _id: { identifier: '$identifier', npsId: '$npsId' }, - total: { $sum: 1 }, - firstId: { $first: '$_id' }, - }, - }, - { - $match: { - total: { $gt: 1 }, - }, - }, - ]) - .toArray(); // since there should not be too much duplicated, it is safe to use .toArray() - - await Promise.all( - duplicated.map((record) => - npsVote.deleteMany({ - _id: { $ne: record.firstId }, - identifier: record._id.identifier, - npsId: record._id.npsId, - }), - ), - ); - - await npsVote.dropIndex('npsId_1_identifier_1'); - await npsVote.createIndex({ npsId: 1, identifier: 1 }, { unique: true }); + // in case server is being updated, we check setup wizard status to determine if should still create the initial channel + const setupWizard = await Settings.getValueById('Show_Setup_Wizard'); + if (setupWizard === 'pending') { + // if still pending for some reason, we need to create the initial channel, so keep the setting as false + return; + } + // if the setup wizard is not pending anymore, we assume initial channel was already created once + await Settings.updateValueById('Initial_Channel_Created', true); }, }); diff --git a/apps/meteor/server/startup/migrations/v264.ts b/apps/meteor/server/startup/migrations/v264.ts index f78e7b661a89..b0f8e6cc0a38 100644 --- a/apps/meteor/server/startup/migrations/v264.ts +++ b/apps/meteor/server/startup/migrations/v264.ts @@ -1,16 +1,41 @@ +import { MongoInternals } from 'meteor/mongo'; + import { addMigration } from '../../lib/migrations'; -import { Settings } from '../../../app/models/server/raw'; addMigration({ version: 264, async up() { - // in case server is being updated, we check setup wizard status to determine if should still create the initial channel - const setupWizard = await Settings.getValueById('Show_Setup_Wizard'); - if (setupWizard === 'pending') { - // if still pending for some reason, we need to create the initial channel, so keep the setting as false - return; - } - // if the setup wizard is not pending anymore, we assume initial channel was already created once - await Settings.updateValueById('Initial_Channel_Created', true); + const { mongo } = MongoInternals.defaultRemoteCollectionDriver(); + const npsVote = mongo.db.collection('rocketchat_nps_vote'); + + const duplicated = await npsVote + .aggregate([ + { + $group: { + _id: { identifier: '$identifier', npsId: '$npsId' }, + total: { $sum: 1 }, + firstId: { $first: '$_id' }, + }, + }, + { + $match: { + total: { $gt: 1 }, + }, + }, + ]) + .toArray(); // since there should not be too much duplicated, it is safe to use .toArray() + + await Promise.all( + duplicated.map((record) => + npsVote.deleteMany({ + _id: { $ne: record.firstId }, + identifier: record._id.identifier, + npsId: record._id.npsId, + }), + ), + ); + + await npsVote.dropIndex('npsId_1_identifier_1'); + await npsVote.createIndex({ npsId: 1, identifier: 1 }, { unique: true }); }, });