mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #26575 from overleaf/jpa-archived-state
[web] remove runtime migration for project.archived/trashed state GitOrigin-RevId: 69064878f3dfdcde3727a4e3eb555deb75c70588
This commit is contained in:
@@ -1,9 +1,56 @@
|
||||
import runScript from '../scripts/convert_archived_state.mjs'
|
||||
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 () => {
|
||||
await runScript('FIRST,SECOND')
|
||||
for (const field of ['archived', 'trashed']) {
|
||||
await migrateField(field)
|
||||
}
|
||||
}
|
||||
|
||||
const rollback = async () => {}
|
||||
|
||||
@@ -10,9 +10,9 @@ class Adapter {
|
||||
if (
|
||||
!process.env.SKIP_TAG_CHECK &&
|
||||
!process.argv.includes('create') &&
|
||||
!(process.argv.includes('-t') || process.argv.includes('--tags'))
|
||||
!(process.argv.includes('-t') || process.argv.includes('--tag'))
|
||||
) {
|
||||
console.error("ERROR: must pass tags using '-t' or '--tags', exiting")
|
||||
console.error("ERROR: must pass tags using '-t' or '--tag', exiting")
|
||||
process.exit(1)
|
||||
}
|
||||
this.params = params || {}
|
||||
|
||||
Reference in New Issue
Block a user