diff --git a/ghost/core/core/server/data/exporter/table-lists.js b/ghost/core/core/server/data/exporter/table-lists.js index 2dfb3ea256..6e031fcce9 100644 --- a/ghost/core/core/server/data/exporter/table-lists.js +++ b/ghost/core/core/server/data/exporter/table-lists.js @@ -31,6 +31,7 @@ const BACKUP_TABLES = [ 'members_paid_subscription_events', 'members_subscribe_events', 'members_product_events', + 'members_created_events', 'members_newsletters', 'comments', 'comment_likes', diff --git a/ghost/core/core/server/data/migrations/versions/5.10/2022-08-16-14-25-add-member-created-events-table.js b/ghost/core/core/server/data/migrations/versions/5.10/2022-08-16-14-25-add-member-created-events-table.js new file mode 100644 index 0000000000..b17e73beb4 --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.10/2022-08-16-14-25-add-member-created-events-table.js @@ -0,0 +1,11 @@ +const {addTable} = require('../../utils'); + +module.exports = addTable('members_created_events', { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + created_at: {type: 'dateTime', nullable: false}, + member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true}, + attribution_id: {type: 'string', maxlength: 24, nullable: true}, + attribution_type: {type: 'string', maxlength: 50, nullable: true}, + attribution_url: {type: 'string', maxlength: 2000, nullable: true}, + source: {type: 'string', maxlength: 50, nullable: false} +}); diff --git a/ghost/core/core/server/data/schema/schema.js b/ghost/core/core/server/data/schema/schema.js index c40c1edc4d..7f2e1882d0 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -474,6 +474,15 @@ 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_created_events: { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + created_at: {type: 'dateTime', nullable: false}, + member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true}, + attribution_id: {type: 'string', maxlength: 24, nullable: true}, + attribution_type: {type: 'string', maxlength: 50, nullable: true}, + attribution_url: {type: 'string', maxlength: 2000, nullable: true}, + source: {type: 'string', maxlength: 50, nullable: false} + }, 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}, diff --git a/ghost/core/core/server/models/member-created-event.js b/ghost/core/core/server/models/member-created-event.js new file mode 100644 index 0000000000..85976c0e6e --- /dev/null +++ b/ghost/core/core/server/models/member-created-event.js @@ -0,0 +1,26 @@ +const errors = require('@tryghost/errors'); +const ghostBookshelf = require('./base'); + +const MemberCreatedEvent = ghostBookshelf.Model.extend({ + tableName: 'members_created_events', + + member() { + return this.belongsTo('Member', 'member_id', 'id'); + }, + + attribution() { + return this.belongsTo('Post', 'attribution_id', 'id'); + } +}, { + async edit() { + throw new errors.IncorrectUsageError({message: 'Cannot edit MemberCreatedEvent'}); + }, + + async destroy() { + throw new errors.IncorrectUsageError({message: 'Cannot destroy MemberCreatedEvent'}); + } +}); + +module.exports = { + MemberCreatedEvent: ghostBookshelf.model('MemberCreatedEvent', MemberCreatedEvent) +}; diff --git a/ghost/core/test/integration/exporter/exporter.test.js b/ghost/core/test/integration/exporter/exporter.test.js index 179a245eae..2e34b3d21e 100644 --- a/ghost/core/test/integration/exporter/exporter.test.js +++ b/ghost/core/test/integration/exporter/exporter.test.js @@ -50,6 +50,8 @@ describe('Exporter', function () { 'members_stripe_customers', 'members_stripe_customers_subscriptions', 'members_subscribe_events', + 'members_created_events', + 'subscription_created_events', 'migrations', 'migrations_lock', 'mobiledoc_revisions', diff --git a/ghost/core/test/unit/server/data/schema/integrity.test.js b/ghost/core/test/unit/server/data/schema/integrity.test.js index ca371659a7..84bd93e5c1 100644 --- a/ghost/core/test/unit/server/data/schema/integrity.test.js +++ b/ghost/core/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 = '45337ae85129a98e4c1b551cc91790da'; + const currentSchemaHash = 'f5f7bc63bf9484bf50a0e554604802b3'; const currentFixturesHash = '0ae1887dd0b42508be946bdbd20d41c8'; const currentSettingsHash = 'd54210758b7054e2174fd34aa2320ad7'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';