mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-10 22:50:46 +02:00
[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:
@@ -1,53 +0,0 @@
|
||||
import { db } from '../app/src/infrastructure/mongodb.js'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
async function updateStringDates() {
|
||||
const users = await db.users.aggregate([
|
||||
{ $unwind: { path: '$emails' } },
|
||||
{
|
||||
$match: { 'emails.confirmedAt': { $exists: true, $type: 'string' } },
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 1,
|
||||
'emails.email': 1,
|
||||
'emails.confirmedAt': 1,
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
let user
|
||||
let count = 0
|
||||
while ((user = await users.next())) {
|
||||
count += 1
|
||||
if (count % 10000 === 0) {
|
||||
console.log(`processed ${count} users`)
|
||||
}
|
||||
const confirmedAt = user.emails.confirmedAt
|
||||
const dateConfirmedAt = new Date(confirmedAt.replace(/ UTC$/, ''))
|
||||
await db.users.updateOne(
|
||||
{
|
||||
_id: user._id,
|
||||
'emails.email': user.emails.email,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
'emails.$.confirmedAt': dateConfirmedAt,
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
console.log(`Updated ${count} confirmedAt strings to dates!`)
|
||||
}
|
||||
|
||||
if (fileURLToPath(import.meta.url) === process.argv[1]) {
|
||||
try {
|
||||
await updateStringDates()
|
||||
process.exit(0)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
export default updateStringDates
|
||||
@@ -1,46 +0,0 @@
|
||||
import { db } from '../app/src/infrastructure/mongodb.js'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
async function updateStringDates() {
|
||||
const users = db.users.find({
|
||||
splitTests: { $exists: true },
|
||||
})
|
||||
|
||||
let user
|
||||
let count = 0
|
||||
while ((user = await users.next())) {
|
||||
count += 1
|
||||
if (count % 10000 === 0) {
|
||||
console.log(`processed ${count} users...`)
|
||||
}
|
||||
|
||||
const splitTests = user.splitTests
|
||||
for (const splitTestKey of Object.keys(splitTests)) {
|
||||
for (const variantIndex in splitTests[splitTestKey]) {
|
||||
splitTests[splitTestKey][variantIndex].assignedAt = new Date(
|
||||
splitTests[splitTestKey][variantIndex].assignedAt
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
await db.users.updateOne(
|
||||
{
|
||||
_id: user._id,
|
||||
},
|
||||
{ $set: { splitTests } }
|
||||
)
|
||||
}
|
||||
console.log(`Updated ${count} assignedAt strings to dates!`)
|
||||
}
|
||||
|
||||
if (fileURLToPath(import.meta.url) === process.argv[1]) {
|
||||
try {
|
||||
await updateStringDates()
|
||||
process.exit(0)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
export default updateStringDates
|
||||
Reference in New Issue
Block a user