Added the MemberCancelEvent model

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

- This event stores the members' subscription cancelations.
This commit is contained in:
Thibaut Patel 2022-03-08 17:51:36 +01:00 committed by Thibaut Patel
parent 49d393c88f
commit 4ce9a5a167
6 changed files with 46 additions and 1 deletions

View File

@ -31,6 +31,7 @@ const BACKUP_TABLES = [
'mobiledoc_revisions', 'mobiledoc_revisions',
'email_batches', 'email_batches',
'email_recipients', 'email_recipients',
'members_cancel_events',
'members_payment_events', 'members_payment_events',
'members_login_events', 'members_login_events',
'members_email_change_events', 'members_email_change_events',

View File

@ -0,0 +1,8 @@
const {addTable} = require('../../utils');
module.exports = addTable('members_cancel_events', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
from_plan: {type: 'string', maxlength: 255, nullable: false},
created_at: {type: 'dateTime', nullable: false}
});

View File

@ -438,6 +438,12 @@ module.exports = {
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true}, product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0} sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
}, },
members_cancel_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
from_plan: {type: 'string', maxlength: 255, nullable: false},
created_at: {type: 'dateTime', nullable: false}
},
members_payment_events: { members_payment_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true}, id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true}, member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},

View File

@ -0,0 +1,28 @@
const errors = require('@tryghost/errors');
const ghostBookshelf = require('./base');
const MemberCancelEvent = ghostBookshelf.Model.extend({
tableName: 'members_cancel_events',
member() {
return this.belongsTo('Member', 'member_id', 'id');
}
}, {
async edit() {
throw new errors.IncorrectUsageError({message: 'Cannot edit MemberCancelEvent'});
},
async destroy() {
throw new errors.IncorrectUsageError({message: 'Cannot destroy MemberCancelEvent'});
}
});
const MemberCancelEvents = ghostBookshelf.Collection.extend({
model: MemberCancelEvent
});
module.exports = {
MemberCancelEvent: ghostBookshelf.model('MemberCancelEvent', MemberCancelEvent),
MemberCancelEvents: ghostBookshelf.collection('MemberCancelEvents', MemberCancelEvents)
};

View File

@ -33,6 +33,7 @@ describe('Exporter', function () {
'invites', 'invites',
'labels', 'labels',
'members', 'members',
'members_cancel_events',
'members_email_change_events', 'members_email_change_events',
'members_labels', 'members_labels',
'members_login_events', 'members_login_events',
@ -91,6 +92,7 @@ describe('Exporter', function () {
'mobiledoc_revisions', 'mobiledoc_revisions',
'email_batches', 'email_batches',
'email_recipients', 'email_recipients',
'members_cancel_events',
'members_payment_events', 'members_payment_events',
'members_login_events', 'members_login_events',
'members_email_change_events', 'members_email_change_events',

View File

@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
*/ */
describe('DB version integrity', function () { describe('DB version integrity', function () {
// Only these variables should need updating // Only these variables should need updating
const currentSchemaHash = '821b2327490e3bebdc62cd54d12932e0'; const currentSchemaHash = 'b7867be4de694b4592d748c0367064b5';
const currentFixturesHash = '84be2bb1d62b384260b72ebfc20f81dc'; const currentFixturesHash = '84be2bb1d62b384260b72ebfc20f81dc';
const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230'; const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';