first commit

This commit is contained in:
2025-04-24 13:11:28 +08:00
commit ff9c54d5e4
5960 changed files with 834111 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
import { db } from '../../app/src/infrastructure/mongodb.js'
import { ensureMongoTimeout } from '../helpers/env_variable_helper.mjs'
// Ensure default mongo query timeout has been increased 1h
if (!process.env.MONGO_SOCKET_TIMEOUT) {
ensureMongoTimeout(360000)
}
async function main() {
await checkAllProjectsAreMigrated()
await setAllowDowngradeToFalse()
await deleteHistoryCollections()
console.log('Legacy history data cleaned up successfully')
process.exit(0)
}
async function checkAllProjectsAreMigrated() {
console.log('checking all projects are migrated to Full Project History')
const count = await db.projects.countDocuments({
'overleaf.history.display': { $ne: true },
})
if (count === 0) {
console.log('All projects are migrated to Full Project History')
} else {
console.error(
`There are ${count} projects that are not migrated to Full Project History` +
` please complete the migration before running this script again.`
)
process.exit(1)
}
}
async function setAllowDowngradeToFalse() {
console.log('unsetting `allowDowngrade` flag in all projects')
await db.projects.updateMany(
{
'overleaf.history.id': { $exists: true },
'overleaf.history.allowDowngrade': true,
},
{ $unset: { 'overleaf.history.allowDowngrade': 1 } }
)
console.log('unsetting `allowDowngrade` flag in all projects - Done')
}
async function deleteHistoryCollections() {
await gracefullyDropCollection(db.docHistory)
await gracefullyDropCollection(db.docHistoryIndex)
await gracefullyDropCollection(db.projectHistoryMetaData)
}
async function gracefullyDropCollection(collection) {
const collectionName = collection.collectionName
console.log(`removing \`${collectionName}\` data`)
try {
await collection.drop()
} catch (err) {
if (err.code === 26) {
// collection already deleted
console.log(`removing \`${collectionName}\` data - Already removed`)
} else {
throw err
}
}
console.log(`removing \`${collectionName}\` data - Done`)
}
try {
await main()
} catch (err) {
console.error(err)
process.exit(1)
}

View File

@@ -0,0 +1,119 @@
import HistoryRangesSupportMigration from '../../app/src/Features/History/HistoryRangesSupportMigration.mjs'
import minimist from 'minimist'
async function main() {
const {
projectIds,
ownerIds,
minId,
maxId,
maxCount,
direction,
force,
stopOnError,
quickOnly,
concurrency,
} = parseArgs()
await HistoryRangesSupportMigration.promises.migrateProjects({
projectIds,
ownerIds,
minId,
maxId,
maxCount,
direction,
force,
stopOnError,
quickOnly,
concurrency,
})
}
function usage() {
console.error(`Usage: migrate_ranges_support.mjs [OPTIONS]
Options:
--help Print this help
--owner-id Migrate all projects owned by this owner
--project-id Migrate this project
--min-id Migrate projects from this id
--max-id Migrate projects to this id
--max-count Migrate at most this number of projects
--all Migrate all projects
--backwards Disable history ranges support for selected project ids
--force Migrate projects even if they were already migrated
--stop-on-error Stop after first migration error
--quick-only Do not try a resync migration if quick migration fails
--concurrency How many jobs to run in parallel
`)
}
function parseArgs() {
const args = minimist(process.argv.slice(2), {
boolean: ['backwards', 'help', 'all', 'force', 'quick-only'],
string: ['owner-id', 'project-id', 'min-id', 'max-id'],
})
if (args.help) {
usage()
process.exit(0)
}
const direction = args.backwards ? 'backwards' : 'forwards'
const ownerIds = arrayOpt(args['owner-id'])
const projectIds = arrayOpt(args['project-id'])
const minId = args['min-id']
const maxId = args['max-id']
const maxCount = args['max-count']
const force = args.force
const stopOnError = args['stop-on-error']
const quickOnly = args['quick-only']
const concurrency = args.concurrency ?? 1
const all = args.all
if (
!all &&
ownerIds == null &&
projectIds == null &&
minId == null &&
maxId == null &&
maxCount == null
) {
console.error(
'Please specify at least one filter, or --all to process all projects\n'
)
usage()
process.exit(1)
}
return {
ownerIds,
projectIds,
minId,
maxId,
maxCount,
direction,
force,
stopOnError,
quickOnly,
concurrency,
}
}
function arrayOpt(value) {
if (typeof value === 'string') {
return [value]
} else if (Array.isArray(value)) {
return value
} else {
return undefined
}
}
try {
await main()
process.exit(0)
} catch (error) {
console.error(error)
process.exit(1)
}