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

* [web] fix typo in ESM migration of a db migration * [web] migrate old migration to ESM * [web] use batchedUpdate for bulk updates in old migrations GitOrigin-RevId: a984f785c577c2ac4125c947b8a3efffa57e1eb7
61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
|
|
|
|
const tags = ['saas']
|
|
|
|
const migrate = async client => {
|
|
const { db } = client
|
|
// 'recurly' -> 'recurlyStatus'
|
|
await batchedUpdate(
|
|
db.subscriptions,
|
|
{
|
|
$and: [
|
|
{ recurlyStatus: { $exists: false } },
|
|
{ recurly: { $exists: true } },
|
|
],
|
|
},
|
|
{ $rename: { recurly: 'recurlyStatus' } }
|
|
)
|
|
// some records may have already recached the recurly status, discard old cache
|
|
await batchedUpdate(
|
|
db.subscriptions,
|
|
{
|
|
$and: [
|
|
{ recurlyStatus: { $exists: true } },
|
|
{ recurly: { $exists: true } },
|
|
],
|
|
},
|
|
{ $unset: { recurly: 1 } }
|
|
)
|
|
}
|
|
|
|
const rollback = async client => {
|
|
const { db } = client
|
|
// 'recurlyStatus' -> 'recurly'
|
|
await batchedUpdate(
|
|
db.subscriptions,
|
|
{
|
|
$and: [
|
|
{ recurly: { $exists: false } },
|
|
{ recurlyStatus: { $exists: true } },
|
|
],
|
|
},
|
|
{ $rename: { recurlyStatus: 'recurly' } }
|
|
)
|
|
// some records may have already recached the recurly status, discard old cache
|
|
await batchedUpdate(
|
|
db.subscriptions,
|
|
{
|
|
$and: [
|
|
{ recurlyStatus: { $exists: true } },
|
|
{ recurly: { $exists: true } },
|
|
],
|
|
},
|
|
{ $unset: { recurlyStatus: 1 } }
|
|
)
|
|
}
|
|
|
|
export default {
|
|
tags,
|
|
migrate,
|
|
rollback,
|
|
}
|