0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Migrated comped members to 'comped' status

refs https://github.com/TryGhost/Team/issues/790

In order to track when a member was comped, as well as to differentiate
paid members from comped, we are reintroducing the 'comped' status. This
migration will updated members with a Complimentary Stripe Subscription
to a status of 'comped'. It is essentially a reversal of the 4.6
migration.
This commit is contained in:
Fabien O'Carroll 2021-07-01 13:09:04 +01:00 committed by Fabien 'egg' O'Carroll
parent 6eba445f23
commit 47cf21514e

View file

@ -0,0 +1,46 @@
const logging = require('@tryghost/logging');
const {createTransactionalMigration} = require('../../utils.js');
module.exports = createTransactionalMigration(
async function up(knex) {
const compedMemberIds = (await knex('members')
.select('members.id')
.innerJoin(
'members_stripe_customers',
'members.id',
'members_stripe_customers.member_id'
).innerJoin(
'members_stripe_customers_subscriptions',
function () {
this.on(
'members_stripe_customers.customer_id',
'members_stripe_customers_subscriptions.customer_id'
).onIn(
'members_stripe_customers_subscriptions.status',
['active', 'trialing', 'past_due', 'unpaid']
);
}
).where(
'members_stripe_customers_subscriptions.plan_nickname',
'=',
'Complimentary'
)).map(({id}) => id);
if (compedMemberIds.length === 0) {
logging.info('No Members found with Complimentary subscriptions');
return;
}
logging.info(`Updating ${compedMemberIds.length} Members status from 'paid' -> 'comped'`);
await knex('members')
.update('status', 'comped')
.whereIn('id', compedMemberIds);
},
async function down(knex) {
logging.info('Updating all member "comped" statuses to "paid"');
await knex('members')
.update('status', 'paid')
.where('status', 'comped');
}
);