mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Updated status population to handle comped status (#12651)
refs https://github.com/TryGhost/Ghost/issues/12602 As part of collecting Member event data, we have added a third status for members "comped" - this fixes the population of the column to handle this
This commit is contained in:
parent
964fe222be
commit
da9cd3b9d6
@ -24,10 +24,34 @@ module.exports = createTransactionalMigration(
|
||||
}
|
||||
)).map(({id}) => id);
|
||||
|
||||
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);
|
||||
|
||||
// Umm? Well... The current version of SQLite3 bundled with Ghost supports
|
||||
// a maximum of 999 variables, we use one variable for the SET value
|
||||
// and so we're left with 998 for our WHERE IN clause values
|
||||
const chunkSize = 998;
|
||||
|
||||
const paidMemberIdChunks = chunk(paidMemberIds, chunkSize);
|
||||
|
||||
for (const paidMemberIdsChunk of paidMemberIdChunks) {
|
||||
@ -35,6 +59,14 @@ module.exports = createTransactionalMigration(
|
||||
.update('status', 'paid')
|
||||
.whereIn('id', paidMemberIdsChunk);
|
||||
}
|
||||
|
||||
const compedMemberIdChunks = chunk(compedMemberIds, chunkSize);
|
||||
|
||||
for (const compedMemberIdsChunk of compedMemberIdChunks) {
|
||||
await knex('members')
|
||||
.update('status', 'comped')
|
||||
.whereIn('id', compedMemberIdsChunk);
|
||||
}
|
||||
},
|
||||
async function down(knex) {
|
||||
logging.info('Updating all members status to "free"');
|
||||
|
Loading…
Reference in New Issue
Block a user