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:
parent
cb76b738ce
commit
ee9190b912
1 changed files with 21 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
);
|
Loading…
Add table
Reference in a new issue