mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 04:41:32 +02:00
Fix: unset recent users featuresUpdatedAt after wrong update (#18149)
* Copy previous script
* Remove `featuresUpdatedAt` that was wrongly set on recent users
* Fix! `signupDate` -> `signUpDate`
* Add test on `migration_compile_timeout_60s_to_20s_fixup_new_users.js`
* style: `$unset: { featuresUpdatedAt: 1 }` -> `$unset: { featuresUpdatedAt: '' }`
Co-authored-by: Jakob Ackermann <jakob.ackermann@overleaf.com>
* Add comment on test (https://github.com/overleaf/internal/pull/18149#discussion_r1582999534)
Co-authored-by: Jakob Ackermann <jakob.ackermann@overleaf.com>
---------
Co-authored-by: Jakob Ackermann <jakob.ackermann@overleaf.com>
GitOrigin-RevId: 408f5c7d48e60722aba736167b8e8858e9570d99
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const minimist = require('minimist')
|
||||
const {
|
||||
db,
|
||||
READ_PREFERENCE_SECONDARY,
|
||||
waitForDb,
|
||||
} = require('../app/src/infrastructure/mongodb')
|
||||
const { batchedUpdate } = require('./helpers/batchedUpdate')
|
||||
|
||||
// A few seconds after the previous migration script was run
|
||||
const FEATURES_UPDATED_AT = new Date('2024-04-16T12:41:00Z')
|
||||
|
||||
const query = {
|
||||
'features.compileTimeout': 20,
|
||||
featuresUpdatedAt: FEATURES_UPDATED_AT,
|
||||
signUpDate: { $gt: FEATURES_UPDATED_AT },
|
||||
}
|
||||
|
||||
async function logCount() {
|
||||
const usersToUpdate = await db.users.countDocuments(query, {
|
||||
readPreference: READ_PREFERENCE_SECONDARY,
|
||||
})
|
||||
console.log(
|
||||
`Found ${usersToUpdate} users needing their featuresUpdatedAt removed`
|
||||
)
|
||||
}
|
||||
|
||||
const main = async ({ COMMIT, SKIP_COUNT }) => {
|
||||
console.time('Script Duration')
|
||||
|
||||
await waitForDb()
|
||||
|
||||
if (!SKIP_COUNT) {
|
||||
await logCount()
|
||||
}
|
||||
|
||||
if (COMMIT) {
|
||||
const nModified = await batchedUpdate('users', query, {
|
||||
$unset: { featuresUpdatedAt: 1 },
|
||||
})
|
||||
console.log(`Updated ${nModified} records`)
|
||||
}
|
||||
|
||||
console.timeEnd('Script Duration')
|
||||
}
|
||||
|
||||
const setup = () => {
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
const COMMIT = argv.commit !== undefined
|
||||
const SKIP_COUNT = argv['skip-count'] !== undefined
|
||||
if (!COMMIT) {
|
||||
console.warn('Doing dry run. Add --commit to commit changes')
|
||||
}
|
||||
return { COMMIT, SKIP_COUNT }
|
||||
}
|
||||
|
||||
main(setup())
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
.then(() => process.exit(0))
|
||||
Reference in New Issue
Block a user