overleaf/services/web/scripts/delete_subscriptions.mjs
Jakob Ackermann a7517eefcb Merge pull request #21427 from overleaf/jpa-populate-db-on-import
[web] populate db with collections on import, ahead of waitForDb() call

GitOrigin-RevId: 7eb4cd61c2052187acd9947d7060f54d9822d314
2024-11-01 09:05:15 +00:00

47 lines
1 KiB
JavaScript

import { Subscription } from '../app/src/models/Subscription.js'
import SubscriptionUpdater from '../app/src/Features/Subscription/SubscriptionUpdater.js'
import minimist from 'minimist'
import mongodb from 'mongodb-legacy'
const { ObjectId } = mongodb
const run = async () => {
for (const id of ids) {
console.log('id', id)
const subscription = await Subscription.findOne({ _id: new ObjectId(id) })
await SubscriptionUpdater.promises.deleteSubscription(
subscription,
deleterData
)
console.log('Deleted subscription', id)
}
}
let ids, deleterData
const setup = () => {
const argv = minimist(process.argv.slice(2))
ids = argv.ids
if (!ids) {
console.error('No ids given')
process.exit(1)
}
ids = ids.split(',')
const deleterId = argv.deleterId
if (!deleterId) {
console.error('No deleterId given')
process.exit(1)
}
deleterData = { id: new ObjectId(deleterId) }
}
setup()
try {
await run()
process.exit(0)
} catch (err) {
console.error('Aiee, something went wrong!', err)
process.exit(1)
}