mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #5364 from overleaf/ta-split-test-assignment-date-backfill
Fix SplitTests assignedAt Type GitOrigin-RevId: 1711f8672fb8e1525780f869b847117a66ca86ed
This commit is contained in:
parent
47cd2d7324
commit
735f79ab6a
2 changed files with 58 additions and 0 deletions
|
@ -0,0 +1,11 @@
|
|||
const updateStringDates = require('../scripts/split_tests_assigned_at_to_dates')
|
||||
|
||||
exports.tags = ['saas']
|
||||
|
||||
exports.migrate = async client => {
|
||||
await updateStringDates()
|
||||
}
|
||||
|
||||
exports.rollback = async client => {
|
||||
/* nothing to do */
|
||||
}
|
47
services/web/scripts/split_tests_assigned_at_to_dates.js
Normal file
47
services/web/scripts/split_tests_assigned_at_to_dates.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
const { db, waitForDb } = require('../app/src/infrastructure/mongodb')
|
||||
|
||||
async function updateStringDates() {
|
||||
await waitForDb()
|
||||
const users = await 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 (!module.parent) {
|
||||
updateStringDates()
|
||||
.then(() => {
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = updateStringDates
|
Loading…
Reference in a new issue