Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Reorder unreleased migrations #25508

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 9 additions & 34 deletions apps/meteor/server/startup/migrations/v262.ts
Original file line number Diff line number Diff line change
@@ -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);
},
});
43 changes: 34 additions & 9 deletions apps/meteor/server/startup/migrations/v264.ts
Original file line number Diff line number Diff line change
@@ -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 });
},
});