mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 13:49:00 +02:00
Merge pull request #14383 from overleaf/jpa-server-pro-feature-refresh-migration
[web] add migration for Server Pro/CE to refresh features once GitOrigin-RevId: 799e6aef2ad9ad6806ec369911d56f7a40945098
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
const Settings = require('@overleaf/settings')
|
||||
const logger = require('@overleaf/logger')
|
||||
const { db, waitForDb } = require('../../../app/src/infrastructure/mongodb')
|
||||
const {
|
||||
mergeFeatures,
|
||||
compareFeatures,
|
||||
} = require('../../../app/src/Features/Subscription/FeaturesHelper')
|
||||
const DRY_RUN = !process.argv.includes('--dry-run=false')
|
||||
|
||||
async function main(DRY_RUN, defaultFeatures) {
|
||||
await waitForDb()
|
||||
|
||||
logger.info({ defaultFeatures }, 'default features')
|
||||
|
||||
const cursor = db.users.find(
|
||||
{},
|
||||
{ projection: { _id: 1, email: 1, features: 1 } }
|
||||
)
|
||||
for await (const user of cursor) {
|
||||
const newFeatures = mergeFeatures(user.features, defaultFeatures)
|
||||
const diff = compareFeatures(newFeatures, user.features)
|
||||
if (Object.keys(diff).length > 0) {
|
||||
logger.warn(
|
||||
{
|
||||
userId: user._id,
|
||||
email: user.email,
|
||||
oldFeatures: user.features,
|
||||
newFeatures,
|
||||
},
|
||||
'user features upgraded'
|
||||
)
|
||||
|
||||
if (!DRY_RUN) {
|
||||
await db.users.updateOne(
|
||||
{ _id: user._id },
|
||||
{ $set: { features: newFeatures } }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = main
|
||||
|
||||
if (require.main === module) {
|
||||
if (DRY_RUN) {
|
||||
console.error('---')
|
||||
console.error('Dry-run enabled, use --dry-run=false to commit changes')
|
||||
console.error('---')
|
||||
}
|
||||
main(DRY_RUN, Settings.defaultFeatures)
|
||||
.then(() => {
|
||||
console.log('Done.')
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error({ error })
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user