From 5b914eb939f1c37c10aaa6e66adfb75774a713ce Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 10 Jan 2024 10:17:35 -0300 Subject: [PATCH 1/3] fix multiple indexes creations --- apps/meteor/server/models/raw/BaseRaw.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/meteor/server/models/raw/BaseRaw.ts b/apps/meteor/server/models/raw/BaseRaw.ts index e43bac39b339..5ab3b9802105 100644 --- a/apps/meteor/server/models/raw/BaseRaw.ts +++ b/apps/meteor/server/models/raw/BaseRaw.ts @@ -78,6 +78,8 @@ export abstract class BaseRaw< this.preventSetUpdatedAt = options?.preventSetUpdatedAt ?? false; } + private pendingIndexes: Promise | undefined; + public async createIndexes() { const indexes = this.modelIndexes(); if (this.options?._updatedAtIndexOptions) { @@ -85,7 +87,17 @@ export abstract class BaseRaw< } if (indexes?.length) { - return this.col.createIndexes(indexes); + if (this.pendingIndexes) { + await this.pendingIndexes; + } + + this.pendingIndexes = this.col.createIndexes(indexes) as unknown as Promise; + + void this.pendingIndexes.finally(() => { + this.pendingIndexes = undefined; + }); + + return this.pendingIndexes; } } From 17ec67a94e702c76f9b97ab88b6da4ad41e77b7e Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 10 Jan 2024 13:23:51 -0300 Subject: [PATCH 2/3] check indexes before delete --- apps/meteor/server/startup/migrations/v304.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/meteor/server/startup/migrations/v304.ts b/apps/meteor/server/startup/migrations/v304.ts index db9aa44b4ee0..48cb217643d0 100644 --- a/apps/meteor/server/startup/migrations/v304.ts +++ b/apps/meteor/server/startup/migrations/v304.ts @@ -6,6 +6,16 @@ addMigration({ version: 304, name: 'Drop wrong index from analytics collection', async up() { + const indexes = await Analytics.col.indexes(); + + if ( + indexes.find( + (index) => index.name === 'room._id_1_date_1' && index.partialFilterExpression && index.partialFilterExpression.type === 'rooms', + ) + ) { + return; + } + await Analytics.col.dropIndex('room._id_1_date_1'); await Analytics.createIndexes(); }, From ce6b5447208da0408473127a3872f3d3ea44a396 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 10 Jan 2024 13:28:23 -0300 Subject: [PATCH 3/3] Create fresh-maps-rhyme.md --- .changeset/fresh-maps-rhyme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fresh-maps-rhyme.md diff --git a/.changeset/fresh-maps-rhyme.md b/.changeset/fresh-maps-rhyme.md new file mode 100644 index 000000000000..2a272a3f81a2 --- /dev/null +++ b/.changeset/fresh-maps-rhyme.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +fix: multiple indexes creation error during 304 migration