mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
[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
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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,
|
||||
}
|
||||
Reference in New Issue
Block a user