2024-10-31 08:16:54 -04:00
|
|
|
import { db } from '../app/src/infrastructure/mongodb.js'
|
2024-10-18 07:04:57 -04:00
|
|
|
import { fileURLToPath } from 'url'
|
2021-10-22 03:58:45 -04:00
|
|
|
|
|
|
|
async function updateStringDates() {
|
2024-05-16 09:34:58 -04:00
|
|
|
const users = db.users.find({
|
2021-10-22 03:58:45 -04:00
|
|
|
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!`)
|
|
|
|
}
|
|
|
|
|
2024-10-18 07:04:57 -04:00
|
|
|
if (fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
|
|
try {
|
|
|
|
await updateStringDates()
|
|
|
|
process.exit(0)
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2021-10-22 03:58:45 -04:00
|
|
|
}
|
|
|
|
|
2024-10-18 07:04:57 -04:00
|
|
|
export default updateStringDates
|