mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
Fixed existing members status properties
refs https://github.com/TryGhost/Team/issues/959 Since we had a bug where members with a canceled subscription would have a status of 'comped' we must fix any existing members in this state. We update all members which have no products to a status of 'free', which is the definition of a 'free' member.
This commit is contained in:
parent
74280cfbea
commit
de9efba30c
@ -0,0 +1,38 @@
|
||||
const logging = require('@tryghost/logging');
|
||||
const {chunk: chunkArray} = require('lodash');
|
||||
const {createTransactionalMigration} = require('../../utils.js');
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
async function up(knex) {
|
||||
logging.info('Updating members with no products to "free"');
|
||||
|
||||
const freeMembers = await knex('members')
|
||||
.select('members.id')
|
||||
.leftJoin('members_products', 'members.id', 'members_products.member_id')
|
||||
.where('members.status', '!=', 'free')
|
||||
.whereNull('members_products.member_id');
|
||||
|
||||
if (freeMembers.length === 0) {
|
||||
logging.info('No free members found');
|
||||
return;
|
||||
}
|
||||
|
||||
// SQLite >= 3.32.0 can support 32766 host parameters
|
||||
// We use one for the SET clause, and the rest can be
|
||||
// used to populate the WHERE IN (?... clause.
|
||||
const chunkSize = 32765;
|
||||
|
||||
const freeMembersIds = freeMembers.map(row => row.id);
|
||||
|
||||
const chunks = chunkArray(freeMembersIds, chunkSize);
|
||||
|
||||
for (const chunk of chunks) {
|
||||
await knex('members')
|
||||
.update('status', 'free')
|
||||
.whereIn('id', chunk);
|
||||
}
|
||||
},
|
||||
async function down() {
|
||||
logging.warn('Not reverting members to incorrect status');
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue
Block a user