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

Update some scripts to use Script Runner GitOrigin-RevId: aaa11f94dcfd328c158bb02d1b9fb2adfb1bb146
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import { db } from '../../app/src/infrastructure/mongodb.js'
|
|
import mongodb from 'mongodb-legacy'
|
|
import fs from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { chunkArray } from '../helpers/chunkArray.mjs'
|
|
import { scriptRunner } from '../lib/ScriptRunner.mjs'
|
|
|
|
const { ObjectId } = mongodb
|
|
|
|
async function main() {
|
|
// search for file of users to transition
|
|
const userIdsPath = process.argv[2]
|
|
const userIdsFile = fs.readFileSync(userIdsPath, 'utf8')
|
|
let userIdsList = userIdsFile
|
|
|
|
userIdsList = userIdsList
|
|
.split('\n')
|
|
.filter(id => id?.length)
|
|
.map(id => new ObjectId(id))
|
|
|
|
const chunks = chunkArray(userIdsList)
|
|
console.log(
|
|
`transitioning ${userIdsList.length} users to auto-account-created state in ${chunks.length} chunks`
|
|
)
|
|
|
|
// Iterate over each chunk and update their autoAccountCreated flag
|
|
for (const chunkedIds of chunks) {
|
|
console.log('batch update started')
|
|
await db.users.updateMany(
|
|
{ _id: { $in: chunkedIds } },
|
|
{ $set: { 'writefull.autoCreatedAccount': true } }
|
|
)
|
|
console.log('batch completed')
|
|
}
|
|
}
|
|
|
|
export default main
|
|
|
|
if (fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
try {
|
|
await scriptRunner(main)
|
|
process.exit(0)
|
|
} catch (error) {
|
|
console.error({ error })
|
|
process.exit(1)
|
|
}
|
|
}
|