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: Handle errors on index creation #26094

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -9297,7 +9297,7 @@ __metadata:
human-interval: ~1.0.0
moment-timezone: ~0.5.27
mongodb: ~3.5.0
checksum: cc8c1bbba7545628d9d039c58e701ff65cf07f241f035b731716eec0d5ef906ce09d60c3b321bbfb9e6c641994d1afd23aaeb92d645b33bf7be9942f13574173
checksum: f5f68008298f9482631f1f494e392cd6b8ba7971a3b0ece81ae2abe60f53d67973ff4476156fa5c9c41b8b58c4ccd284e95c545e0523996dfd05f9a80b843e07
languageName: node
linkType: hard

Expand Down