2023-01-26 06:42:34 -05:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
2024-10-02 05:32:13 -04:00
|
|
|
import Helpers from './lib/helpers.mjs'
|
2023-01-26 06:42:34 -05:00
|
|
|
|
2024-10-02 05:32:13 -04:00
|
|
|
const tags = ['saas']
|
2023-01-26 06:42:34 -05:00
|
|
|
|
2024-10-02 05:32:13 -04:00
|
|
|
const migrate = async client => {
|
2023-01-26 06:42:34 -05:00
|
|
|
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 } }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-10-02 05:32:13 -04:00
|
|
|
const rollback = async client => {
|
2023-01-26 06:42:34 -05:00
|
|
|
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 } }
|
|
|
|
)
|
|
|
|
}
|
2024-10-02 05:32:13 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
tags,
|
|
|
|
migrate,
|
|
|
|
rollback,
|
|
|
|
}
|