Added migration to fix incorrect mrr events (#12837)

closes https://github.com/TryGhost/Team/issues/595

Due to a bug in `mrr_delta` calculation, we ended up reducing the MRR delta by twice the original amount when a subscription goes from active to canceled and storing it in `members_paid_subscription_events` table, which is used to show the MRR chart on Dashboard. The way we identify the incorrect events in the table which got the double negative value is by checking if they match certain criteria - Both `from_plan` and `to_plan` have same value as a subscription changes status while being on same plan.

This migration halves the `mrr_delta` for incorrect events to restore the correct MRR change for the site.
This commit is contained in:
Rishabh Garg 2021-04-06 21:14:54 +05:30 committed by GitHub
parent a6b3d5463d
commit dba2a2970b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,13 @@
const {createTransactionalMigration} = require('../../utils');
const logging = require('../../../../../shared/logging');
module.exports = createTransactionalMigration(
async function up(knex) {
logging.info('Fixing incorrect mrr_delta in members_paid_subscription_events table');
await knex.raw('UPDATE members_paid_subscription_events SET mrr_delta = ROUND(mrr_delta / 2) WHERE from_plan = to_plan');
},
async function down(knex) {
logging.info('Reverting mrr_delta to old value in members_paid_subscription_events table');
await knex.raw('UPDATE members_paid_subscription_events SET mrr_delta = ROUND(mrr_delta * 2) WHERE from_plan = to_plan');
}
);