overleaf/services/web/migrations/20230110140452_rename_recurly_cached_status.js
Thomas aa9b07d323 Merge pull request #11445 from overleaf/revert-11432-revert-11154-tm-lg-subscription-recurly-cache-name
Re-instate change property name for recurly status cache to recurlyStatus

GitOrigin-RevId: 3b3415d818629676ee44dbc558a6b87469fd1af0
2023-01-27 09:03:58 +00:00

53 lines
1.2 KiB
JavaScript

/* eslint-disable no-unused-vars */
const Helpers = require('./lib/helpers')
exports.tags = ['saas']
exports.migrate = async client => {
const { db } = client
// 'recurly' -> 'recurlyStatus'
await db.subscriptions.updateMany(
{
$and: [
{ recurlyStatus: { $exists: false } },
{ recurly: { $exists: true } },
],
},
{ $rename: { recurly: 'recurlyStatus' } }
)
// some records may have already recached the recurly status, discard old cache
await db.subscriptions.updateMany(
{
$and: [
{ recurlyStatus: { $exists: true } },
{ recurly: { $exists: true } },
],
},
{ $unset: { recurly: 1 } }
)
}
exports.rollback = async client => {
const { db } = client
// 'recurlyStatus' -> 'recurly'
await db.subscriptions.updateMany(
{
$and: [
{ recurly: { $exists: false } },
{ recurlyStatus: { $exists: true } },
],
},
{ $rename: { recurlyStatus: 'recurly' } }
)
// some records may have already recached the recurly status, discard old cache
await db.subscriptions.updateMany(
{
$and: [
{ recurlyStatus: { $exists: true } },
{ recurly: { $exists: true } },
],
},
{ $unset: { recurlyStatus: 1 } }
)
}