Files
overleaf-cep/tools/migrations/20260616070000_back_fill_users_analyticsId.mjs
T
Jakob AckermannandAndrew Rumble 6323fddbd8 [web] avoid UserAnalyticsIdCache (#33121)
* [web] always provide an analyticsId when registering new users

* [web] add recordEventForMongoUser and use it during login

* [web] use recordEventForMongoUser/recordEventForSession where possible

* [web] use session cache for analyticsId when refreshing features

* [web] add setUserPropertyForMongoUser and use it where possible

* [web] use setUserPropertyForSessionInBackground where possible

* [web] use mongo user for analyticsId when setting utm user properties

* [web] admin-panel: user updated user when sending events

* [web] enforce labsProgram being populated on user object

Co-authored-by: Andrew Rumble <andrew.rumble@overleaf.com>

* [web] revert FeaturesUpdater.refreshFeatures change

* [web] labs: move session maintenance into handler

* [web] analyticsMiddleware: ensure that all users have labsProgram field

* [web] migrate a few more events to recordEventForSession

* [migrations] mark back-fill of db.users.analyticsId as required

* [web] setUserPropertyForSessionInBackground: throw early

---------

Co-authored-by: Andrew Rumble <andrew.rumble@overleaf.com>
GitOrigin-RevId: 19c26bc36abd8c11f0a8f458d25abfb7cbda0bb7
2026-06-17 08:08:32 +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,
}