From ee0a6910ce4c54f7cbb3865a8a9efaee7e449eb2 Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Mon, 4 Apr 2022 18:11:36 +0530 Subject: [PATCH] Added table to store multiple newsletters for member (#14408) refs https://github.com/TryGhost/Team/issues/1469 With multiple newsletters, members will now be able to subscribe to one or more newsletters on the site. Previously, the subscription to default newsletter for a member was controlled via a single boolean `subscribed` column on the member table. This change allows mapping multiple newsletters to a member via new pivot table that stores relation between a member and newsletter. - adds new `members_newsletters` pivot table - update tests --- core/server/data/exporter/table-lists.js | 1 + .../4.43/2022-03-29-14-45-add-members-newsletters-table.js | 7 +++++++ core/server/data/schema/schema.js | 5 +++++ test/integration/exporter/exporter.test.js | 1 + test/unit/server/data/schema/integrity.test.js | 2 +- 5 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 core/server/data/migrations/versions/4.43/2022-03-29-14-45-add-members-newsletters-table.js diff --git a/core/server/data/exporter/table-lists.js b/core/server/data/exporter/table-lists.js index b8f241d077..1801d68d3c 100644 --- a/core/server/data/exporter/table-lists.js +++ b/core/server/data/exporter/table-lists.js @@ -40,6 +40,7 @@ const BACKUP_TABLES = [ 'members_paid_subscription_events', 'members_subscribe_events', 'members_product_events', + 'members_newsletters', 'offers', 'offer_redemptions' ]; diff --git a/core/server/data/migrations/versions/4.43/2022-03-29-14-45-add-members-newsletters-table.js b/core/server/data/migrations/versions/4.43/2022-03-29-14-45-add-members-newsletters-table.js new file mode 100644 index 0000000000..b05c7ac2dd --- /dev/null +++ b/core/server/data/migrations/versions/4.43/2022-03-29-14-45-add-members-newsletters-table.js @@ -0,0 +1,7 @@ +const {addTable} = require('../../utils'); + +module.exports = addTable('members_newsletters', { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true}, + newsletter_id: {type: 'string', maxlength: 24, nullable: false, references: 'newsletters.id', cascadeDelete: true} +}); diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index 2ed070de8a..08ac2b1215 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -729,5 +729,10 @@ module.exports = { }, subscribe_on_signup: {type: 'bool', nullable: false, defaultTo: false}, sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0} + }, + members_newsletters: { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true}, + newsletter_id: {type: 'string', maxlength: 24, nullable: false, references: 'newsletters.id', cascadeDelete: true} } }; diff --git a/test/integration/exporter/exporter.test.js b/test/integration/exporter/exporter.test.js index d3a1eef617..1364be5412 100644 --- a/test/integration/exporter/exporter.test.js +++ b/test/integration/exporter/exporter.test.js @@ -37,6 +37,7 @@ describe('Exporter', function () { 'members_email_change_events', 'members_labels', 'members_login_events', + 'members_newsletters', 'members_paid_subscription_events', 'members_payment_events', 'members_products', diff --git a/test/unit/server/data/schema/integrity.test.js b/test/unit/server/data/schema/integrity.test.js index 6d2a935ed3..b4dadb4152 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 = 'adaab19330ba19ed2d0cba49458c8f21'; + const currentSchemaHash = '8bf6c2996ddd0238d41a9d3e1cb07bd9'; const currentFixturesHash = 'f4dd2a454e1999b6d149cc26ae52ced4'; const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';