mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
* [migrations] make old migrations compatible with --notablescan in mongo Re-running the migration for db.users.emails.reversedHostname on all Server Pro/CE users will not be harmfull. * [monorepo] enable mongo notablescan for all services but web GitOrigin-RevId: e2a710c9de08de9ac2aa9df1f3082d5f1c33ea05
41 lines
939 B
JavaScript
41 lines
939 B
JavaScript
const tags = ['server-ce', 'server-pro']
|
|
|
|
function fixEmails(user) {
|
|
let emails = user.emails
|
|
if (!emails || emails.length === 0) {
|
|
emails = [{ email: user.email, createdAt: new Date() }]
|
|
}
|
|
for (let i = 0; i < emails.length; i++) {
|
|
const reversedHostname = emails[i].email
|
|
.split('@')[1]
|
|
.split('')
|
|
.reverse()
|
|
.join('')
|
|
if (emails[i].reversedHostname !== reversedHostname) {
|
|
emails = emails.slice()
|
|
emails[i].reversedHostname = reversedHostname
|
|
}
|
|
}
|
|
return emails
|
|
}
|
|
|
|
const migrate = async client => {
|
|
const { db } = client
|
|
|
|
const cursor = db.users.find({}, { projection: { email: 1, emails: 1 } })
|
|
for await (const user of cursor) {
|
|
const emails = fixEmails(user)
|
|
if (user.emails !== emails) {
|
|
await db.users.updateOne({ _id: user._id }, { $set: { emails } })
|
|
}
|
|
}
|
|
}
|
|
|
|
const rollback = async () => {}
|
|
|
|
export default {
|
|
tags,
|
|
migrate,
|
|
rollback,
|
|
}
|