mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-23 23:00:08 +02:00

* [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
40 lines
921 B
JavaScript
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,
|
|
}
|