diff --git a/core/server/data/exporter/table-lists.js b/core/server/data/exporter/table-lists.js index 66a6f044a3..cd354454c2 100644 --- a/core/server/data/exporter/table-lists.js +++ b/core/server/data/exporter/table-lists.js @@ -31,6 +31,7 @@ const BACKUP_TABLES = [ 'mobiledoc_revisions', 'email_batches', 'email_recipients', + 'members_cancel_events', 'members_payment_events', 'members_login_events', 'members_email_change_events', diff --git a/core/server/data/migrations/versions/4.40/2022-03-07-14-37-add-members-cancel-events-table.js b/core/server/data/migrations/versions/4.40/2022-03-07-14-37-add-members-cancel-events-table.js new file mode 100644 index 0000000000..e4bfe50998 --- /dev/null +++ b/core/server/data/migrations/versions/4.40/2022-03-07-14-37-add-members-cancel-events-table.js @@ -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} +}); diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index 014332ce0d..4ea90b7798 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -438,6 +438,12 @@ module.exports = { product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true}, 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: { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true}, diff --git a/core/server/models/member-cancel-event.js b/core/server/models/member-cancel-event.js new file mode 100644 index 0000000000..04407c8311 --- /dev/null +++ b/core/server/models/member-cancel-event.js @@ -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) +}; + diff --git a/test/integration/exporter/exporter.test.js b/test/integration/exporter/exporter.test.js index d6c6204b9b..0a6b414c0e 100644 --- a/test/integration/exporter/exporter.test.js +++ b/test/integration/exporter/exporter.test.js @@ -33,6 +33,7 @@ describe('Exporter', function () { 'invites', 'labels', 'members', + 'members_cancel_events', 'members_email_change_events', 'members_labels', 'members_login_events', @@ -91,6 +92,7 @@ describe('Exporter', function () { 'mobiledoc_revisions', 'email_batches', 'email_recipients', + 'members_cancel_events', 'members_payment_events', 'members_login_events', 'members_email_change_events', diff --git a/test/unit/server/data/schema/integrity.test.js b/test/unit/server/data/schema/integrity.test.js index 22668190ca..3a0e80d1e2 100644 --- a/test/unit/server/data/schema/integrity.test.js +++ b/test/unit/server/data/schema/integrity.test.js @@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = '821b2327490e3bebdc62cd54d12932e0'; + const currentSchemaHash = 'b7867be4de694b4592d748c0367064b5'; const currentFixturesHash = '84be2bb1d62b384260b72ebfc20f81dc'; const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';