0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Populated type column of existing events (#14437)

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

Currently we only have three event types: created, updated & expired.

A created event always has a `from_plan` of null

An updated event will always have a different `to_plan` and `from_plan`
as the subscription has changed tier/cadence.

An expired event _should_ have a `to_plan` of null, but due to a bug we
have events with the same `from_plan` and `to_plan`.
This commit is contained in:
Fabien 'egg' O'Carroll 2022-04-11 11:41:44 +01:00 committed by GitHub
parent cb76b738ce
commit ee9190b912
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,21 @@
const logging = require('@tryghost/logging');
const {createTransactionalMigration} = require('../../utils');
module.exports = createTransactionalMigration(
async function up(knex) {
logging.info('Setting "type" to "updated" for events with different to_plan & from_plan');
await knex('members_paid_subscription_events').update('type', 'updated').whereNotNull('from_plan').whereNotNull('to_plan').whereRaw('to_plan != from_plan');
logging.info('Setting "type" to "expired" for events with null to_plan or the same to_plan & from_plan');
await knex('members_paid_subscription_events').update('type', 'expired').whereNull('to_plan').whereNotNull('from_plan');
await knex('members_paid_subscription_events').update('type', 'expired').whereRaw('from_plan = to_plan');
logging.info('Setting "type" to "created" for events with null from_plan');
await knex('members_paid_subscription_events').update('type', 'created').whereNull('from_plan').whereNotNull('to_plan');
},
async function down(knex) {
logging.info('Setting "type" to null for all rows in "members_paid_subscriptions events"');
await knex('members_paid_subscription_events').update('type', null);
}
);