Skip to content

Commit

Permalink
fix: migration to drop User.createdBy field
Browse files Browse the repository at this point in the history
  • Loading branch information
rupl committed Dec 6, 2021
1 parent 18f5a7c commit 2d4d43b
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @module migratePasswordExpiry
* @description Removes all properties related to password expiry.
* @module migrateCreatedBy
* @description Removes the createdBy property from all users.
*/
const mongoose = require('mongoose');
const config = require('../config/env');
Expand All @@ -15,16 +15,14 @@ mongoose.connect(store.uri, store.options);
const User = require('../api/models/User');

async function run() {
// Drop fields related to password expiry notifications from all users.
// Drop the `createdBy` field from all users.
await User.collection.updateMany({}, {
$unset: {
passwordResetAlert30days: 1,
passwordResetAlert7days: 1,
passwordResetAlert: 1,
createdBy: 1,
},
}).catch((err) => {
logger.warn(
`[commands->migratePasswordExpiry] ${err.message}`,
`[commands->migrateCreatedBy] ${err.message}`,
{
migration: true,
fail: true,
Expand All @@ -35,7 +33,7 @@ async function run() {

// Log it
logger.info(
'[commands->migratePasswordExpiry] Removed passwordResetAlert30days, passwordResetAlert7days, passwordResetAlert fields from all users',
'[commands->migrateCreatedBy] Removed createdBy field from all users',
{
migration: true,
},
Expand All @@ -49,7 +47,7 @@ async function run() {
await run();
}()).catch((err) => {
logger.error(
`[commands->migratePasswordExpiry] ${err.message}`,
`[commands->migrateCreatedBy] ${err.message}`,
{
migration: true,
fail: true,
Expand Down

0 comments on commit 2d4d43b

Please # to comment.