diff --git a/core/server/data/migrations/versions/4.2/01-fix-incorrect-mrr-delta-events.js b/core/server/data/migrations/versions/4.2/01-fix-incorrect-mrr-delta-events.js new file mode 100644 index 0000000000..7e24200303 --- /dev/null +++ b/core/server/data/migrations/versions/4.2/01-fix-incorrect-mrr-delta-events.js @@ -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'); + } +);