[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
This commit is contained in:
Jakob Ackermann
2025-06-26 08:04:46 +00:00
committed by Copybot
parent 1543f0a53e
commit 19980b41b8
6 changed files with 251 additions and 107 deletions
@@ -1,12 +1,35 @@
import updateStringDates from '../scripts/confirmed_at_to_dates.mjs'
import { db } from '../app/src/infrastructure/mongodb.js'
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
const tags = ['saas']
const migrate = async client => {
await updateStringDates()
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 client => {
const rollback = async () => {
/* nothing to do */
}
@@ -1,12 +1,29 @@
import updateStringDates from '../scripts/split_tests_assigned_at_to_dates.mjs'
import { db } from '../app/src/infrastructure/mongodb.js'
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
const tags = ['saas']
const migrate = async client => {
await updateStringDates()
const migrate = async () => {
await batchedUpdate(
db.users,
{ splitTests: { $exists: true } },
async function (batch) {
for (const user of batch) {
const splitTests = user.splitTests
for (const splitTest of Object.values(user.splitTests)) {
for (const variant of splitTest) {
variant.assignedAt = new Date(variant.assignedAt)
}
}
await db.users.updateOne({ _id: user._id }, { $set: { splitTests } })
}
},
{ splitTests: 1 }
)
}
const rollback = async client => {
const rollback = async () => {
/* nothing to do */
}