From a7b2af85fc9323304d6d737efdd666219cf0d303 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 30 Jan 2020 23:53:34 +0000 Subject: [PATCH] fix: fixes bug related to migration error (#2816) When a user did not have any comments when the migration 1575649180000 hits, they are not migrated to get a `commentCounts` property. This migration finds those users without `commentCounts` and sets them to the empty comment counts. Co-authored-by: Kim Gardner --- .../1580404849316_user_comment_counts.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/core/server/services/migrate/migrations/1580404849316_user_comment_counts.ts diff --git a/src/core/server/services/migrate/migrations/1580404849316_user_comment_counts.ts b/src/core/server/services/migrate/migrations/1580404849316_user_comment_counts.ts new file mode 100644 index 000000000..44a485b36 --- /dev/null +++ b/src/core/server/services/migrate/migrations/1580404849316_user_comment_counts.ts @@ -0,0 +1,33 @@ +import { Db } from "mongodb"; + +import Migration from "coral-server/services/migrate/migration"; +import collections from "coral-server/services/mongodb/collections"; + +export default class extends Migration { + public async up(mongo: Db, tenantID: string) { + const result = await collections.users(mongo).updateMany( + { tenantID, commentCounts: null }, + { + $set: { + commentCounts: { + status: { + APPROVED: 0, + NONE: 0, + PREMOD: 0, + REJECTED: 0, + SYSTEM_WITHHELD: 0, + }, + }, + }, + } + ); + + this.log(tenantID).warn( + { + matchedCount: result.matchedCount, + modifiedCount: result.modifiedCount, + }, + "applied fix to users" + ); + } +}