mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-23 23:00:08 +02:00

[web] remove runtime migration for project.archived/trashed state GitOrigin-RevId: 69064878f3dfdcde3727a4e3eb555deb75c70588
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
|
|
import { promiseMapWithLimit } from '@overleaf/promise-utils'
|
|
import { db } from '../app/src/infrastructure/mongodb.js'
|
|
import _ from 'lodash'
|
|
|
|
const tags = ['server-ce', 'server-pro']
|
|
|
|
const WRITE_CONCURRENCY = parseInt(process.env.WRITE_CONCURRENCY, 10) || 10
|
|
|
|
function getAllUserIds(project) {
|
|
return _.unionWith(
|
|
[project.owner_ref],
|
|
project.collaberator_refs,
|
|
project.readOnly_refs,
|
|
project.tokenAccessReadAndWrite_refs,
|
|
project.tokenAccessReadOnly_refs,
|
|
(a, b) => a.toString() === b.toString()
|
|
)
|
|
}
|
|
|
|
async function migrateField(field) {
|
|
await batchedUpdate(
|
|
db.projects,
|
|
{ [field]: false },
|
|
{ $set: { [field]: [] } }
|
|
)
|
|
|
|
await batchedUpdate(
|
|
db.projects,
|
|
{ [field]: true },
|
|
async nextBatch => {
|
|
await promiseMapWithLimit(WRITE_CONCURRENCY, nextBatch, async project => {
|
|
await db.projects.updateOne(
|
|
{ _id: project._id },
|
|
{ $set: { [field]: getAllUserIds(project) } }
|
|
)
|
|
})
|
|
},
|
|
{
|
|
_id: 1,
|
|
owner_ref: 1,
|
|
collaberator_refs: 1,
|
|
readOnly_refs: 1,
|
|
tokenAccessReadAndWrite_refs: 1,
|
|
tokenAccessReadOnly_refs: 1,
|
|
}
|
|
)
|
|
}
|
|
|
|
const migrate = async () => {
|
|
for (const field of ['archived', 'trashed']) {
|
|
await migrateField(field)
|
|
}
|
|
}
|
|
|
|
const rollback = async () => {}
|
|
|
|
export default {
|
|
tags,
|
|
migrate,
|
|
rollback,
|
|
}
|