Files
overleaf-cep/tools/migrations/20260424120000_back_fill_users_analyticsId.mjs
Jakob Ackermann 50abfe8f0c [migrations] add migration for back filling db.users.analyticsId (#33115)
* [migrations] add migration for back filling db.users.analyticsId

Co-authored-by: Davinder Singh <davinder.singh@overleaf.com>

* [web] add acceptance test for backfilling db.users.analyticsId

---------

Co-authored-by: Davinder Singh <davinder.singh@overleaf.com>
GitOrigin-RevId: a0840969ac0c4c84e874c6f00cf0a78857a4bb06
2026-04-30 08:06:38 +00:00

25 lines
545 B
JavaScript

import { db } from './lib/mongodb.mjs'
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
const tags = ['saas', 'server-ce', 'server-pro']
const migrate = async () => {
await batchedUpdate(db.users, { analyticsId: { $exists: false } }, [
{ $set: { analyticsId: { $toString: '$_id' } } },
])
}
const rollback = async () => {
await batchedUpdate(
db.users,
{ $expr: { $eq: [{ $strLenCP: '$analyticsId' }, 24] } },
{ $unset: { analyticsId: 1 } }
)
}
export default {
tags,
migrate,
rollback,
}