overleaf-cep/services/web/migrations/20210726083523_convert_confirmedAt_strings_to_dates.mjs
Jakob Ackermann 19980b41b8 [web] switch migrations for fixing dates to batchedUpdate (#26582)
* [web] switch migration for fixing confirmedAt dates to batchedUpdate

* [web] switch migration for fixing assignedAt dates to batchedUpdate

* [web] make eslint happy

GitOrigin-RevId: d898d28dc2aa1084e8d3af20b98f49e3fda8a1c6
2025-06-26 08:04:46 +00:00

40 lines
921 B
JavaScript

import { db } from '../app/src/infrastructure/mongodb.js'
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
const tags = ['saas']
const migrate = async () => {
await batchedUpdate(
db.users,
{ 'emails.confirmedAt': { $type: 'string' } },
async function (batch) {
for (const user of batch) {
for (const email of user.emails) {
if (typeof email.confirmedAt === 'string') {
await db.users.updateOne(
{ _id: user._id, 'emails.email': email.email },
{
$set: {
'emails.$.confirmedAt': new Date(
email.confirmedAt.replace(/ UTC$/, '')
),
},
}
)
}
}
}
},
{ emails: 1 }
)
}
const rollback = async () => {
/* nothing to do */
}
export default {
tags,
migrate,
rollback,
}