From 83be54af422652cd94f46018406df76b3e97342d Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Tue, 29 Nov 2022 14:38:15 +0700 Subject: [PATCH] Added suppressions table and model refs https://github.com/TryGhost/Team/issues/2317 This table is used for persisting the email suppression list. We don't have a member_id column because emails, not members are suppressed. --- .../core/server/data/exporter/table-lists.js | 3 ++- .../2022-11-24-10-36-add-suppressions-table.js | 9 +++++++++ ghost/core/core/server/data/schema/schema.js | 17 +++++++++++++++++ ghost/core/core/server/models/suppression.js | 9 +++++++++ .../unit/server/data/schema/integrity.test.js | 2 +- .../test/unit/server/models/suppression.test.js | 8 ++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 ghost/core/core/server/data/migrations/versions/5.25/2022-11-24-10-36-add-suppressions-table.js create mode 100644 ghost/core/core/server/models/suppression.js create mode 100644 ghost/core/test/unit/server/models/suppression.test.js diff --git a/ghost/core/core/server/data/exporter/table-lists.js b/ghost/core/core/server/data/exporter/table-lists.js index 5d73e72e5c..cda5721fcb 100644 --- a/ghost/core/core/server/data/exporter/table-lists.js +++ b/ghost/core/core/server/data/exporter/table-lists.js @@ -43,7 +43,8 @@ const BACKUP_TABLES = [ 'jobs', 'redirects', 'members_click_events', - 'members_feedback' + 'members_feedback', + 'suppressions' ]; // NOTE: exposing only tables which are going to be included in a "default" export file diff --git a/ghost/core/core/server/data/migrations/versions/5.25/2022-11-24-10-36-add-suppressions-table.js b/ghost/core/core/server/data/migrations/versions/5.25/2022-11-24-10-36-add-suppressions-table.js new file mode 100644 index 0000000000..3808a1fdae --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.25/2022-11-24-10-36-add-suppressions-table.js @@ -0,0 +1,9 @@ +const {addTable} = require('../../utils'); + +module.exports = addTable('suppressions', { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + email_address: {type: 'string', maxlength: 191, nullable: false, unique: true}, + email_id: {type: 'string', maxlength: 24, nullable: true, references: 'emails.id'}, + reason: {type: 'string', maxlength: 50, nullable: false}, + created_at: {type: 'dateTime', nullable: false} +}); diff --git a/ghost/core/core/server/data/schema/schema.js b/ghost/core/core/server/data/schema/schema.js index badee4efd6..15f737f916 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -949,5 +949,22 @@ module.exports = { post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', cascadeDelete: true}, created_at: {type: 'dateTime', nullable: false}, updated_at: {type: 'dateTime', nullable: true} + }, + suppressions: { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + email_address: {type: 'string', maxlength: 191, nullable: false, unique: true, validations: {isEmail: true}}, + email_id: {type: 'string', maxlength: 24, nullable: true, references: 'emails.id'}, + reason: { + type: 'string', + maxlength: 50, + nullable: false, + validations: { + isIn: [[ + 'spam', + 'bounce' + ]] + } + }, + created_at: {type: 'dateTime', nullable: false} } }; diff --git a/ghost/core/core/server/models/suppression.js b/ghost/core/core/server/models/suppression.js new file mode 100644 index 0000000000..e1809099f4 --- /dev/null +++ b/ghost/core/core/server/models/suppression.js @@ -0,0 +1,9 @@ +const ghostBookshelf = require('./base'); + +const Suppression = ghostBookshelf.Model.extend({ + tableName: 'suppressions' +}); + +module.exports = { + Suppression: ghostBookshelf.model('Suppression', Suppression) +}; 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 64dee1b39a..3c1d5119b6 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 = '4b749aee6b3c823c3ea27e2c936cde17'; + const currentSchemaHash = 'ded409c0ead434761073836b8b6975c6'; const currentFixturesHash = 'dcb7ba7c66b4b98d6c26a722985e756a'; const currentSettingsHash = '9acce72858e75420b831297718595bbd'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; diff --git a/ghost/core/test/unit/server/models/suppression.test.js b/ghost/core/test/unit/server/models/suppression.test.js new file mode 100644 index 0000000000..0a6c9f6b0a --- /dev/null +++ b/ghost/core/test/unit/server/models/suppression.test.js @@ -0,0 +1,8 @@ +const assert = require('assert'); +const Suppression = require('../../../../core/server/models/suppression'); + +describe('Suppression', function () { + it('exists', function () { + assert(Suppression); + }); +});