Skip to content

Commit

Permalink
Chore: Handle errors on index creation (#26094)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Jul 1, 2022
1 parent 3394c0d commit a252340
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/server/models/raw/BaseRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export abstract class BaseRaw<T, C extends DefaultFields<T> = undefined> impleme
const indexes = this.modelIndexes();
if (indexes?.length) {
this.col.createIndexes(indexes).catch((e) => {
console.warn(`Error creating indexes for ${this.name}`, e);
console.warn(`Some indexes for collection '${this.name}' could not be created:\n\t${e.message}`);
});
}

Expand Down
9 changes: 7 additions & 2 deletions apps/meteor/server/startup/migrations/v203.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { addMigration } from '../../lib/migrations';
addMigration({
version: 203,
async up() {
await Avatars.col.dropIndex('name_1');
await Avatars.col.createIndex({ name: 1 }, { sparse: true });
try {
await Avatars.col.dropIndex('name_1');
await Avatars.col.createIndex({ name: 1 }, { sparse: true });
} catch (error: unknown) {
console.warn('Error recreating index for rocketchat_avatars, continuing...');
console.warn(error);
}
},
});
10 changes: 7 additions & 3 deletions apps/meteor/server/startup/migrations/v218.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { addMigration } from '../../lib/migrations';

addMigration({
version: 218,
up() {
// TODO test if dropIndex do not raise exceptions.
Statistics.col.dropIndex('createdAt_1');
async up() {
try {
await Statistics.col.dropIndex('createdAt_1');
} catch (error: unknown) {
console.warn('Error droping index for rocketchat_statistics, continuing...');
console.warn(error);
}
},
});
9 changes: 7 additions & 2 deletions apps/meteor/server/startup/migrations/v263.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ addMigration({
const { mongo } = MongoInternals.defaultRemoteCollectionDriver();
const integrationHistory = mongo.db.collection('rocketchat_integration_history');

await integrationHistory.dropIndex('_updatedAt_1');
await integrationHistory.createIndex({ _updatedAt: 1 }, { expireAfterSeconds: 30 * 24 * 60 * 60 });
try {
await integrationHistory.dropIndex('_updatedAt_1');
await integrationHistory.createIndex({ _updatedAt: 1 }, { expireAfterSeconds: 30 * 24 * 60 * 60 });
} catch (error: unknown) {
console.warn('Error recreating index for rocketchat_integration_history, continuing...');
console.warn(error);
}
},
});
9 changes: 7 additions & 2 deletions apps/meteor/server/startup/migrations/v264.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ addMigration({
),
);

await npsVote.dropIndex('npsId_1_identifier_1');
await npsVote.createIndex({ npsId: 1, identifier: 1 }, { unique: true });
try {
await npsVote.dropIndex('npsId_1_identifier_1');
await npsVote.createIndex({ npsId: 1, identifier: 1 }, { unique: true });
} catch (error: unknown) {
console.warn('Error recreating index for rocketchat_nps_vote, continuing...');
console.warn(error);
}
},
});
7 changes: 6 additions & 1 deletion apps/meteor/server/startup/migrations/v273.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { addMigration } from '../../lib/migrations';
addMigration({
version: 273,
async up() {
return appTokensCollection.rawCollection().dropIndex('userId_1');
try {
return appTokensCollection.rawCollection().dropIndex('userId_1');
} catch (error: unknown) {
console.warn('Error dropping index for _raix_push_app_tokens, continuing...');
console.warn(error);
}
},
});
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9348,7 +9348,7 @@ __metadata:
human-interval: ~1.0.0
moment-timezone: ~0.5.27
mongodb: ~3.5.0
checksum: acb4ebb7e7356f6e53e810d821eb6aa3d88bbfb9e85183e707517bee6d1eea1f189f38bdf0dd2b91360492ab7643134d510c320d2523d86596498ab98e59735b
checksum: f5f68008298f9482631f1f494e392cd6b8ba7971a3b0ece81ae2abe60f53d67973ff4476156fa5c9c41b8b58c4ccd284e95c545e0523996dfd05f9a80b843e07
languageName: node
linkType: hard

Expand Down

0 comments on commit a252340

Please sign in to comment.