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 <kgardnr@gmail.com>
This commit is contained in:
Wyatt Johnson
2020-01-30 18:53:34 -05:00
committed by GitHub
co-authored by Kim Gardner
parent 516611e289
commit a7b2af85fc
@@ -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"
);
}
}