Added migrations to drop and recreate the suppressions table (#16070)

There are currently two issues with the suppressions table:
  - We have some incorrect rows
  - We have missing UNIQUE constraints

We want to completely wipe the tables and start fresh, as well as make
sure that the UNIQUE constraints are added, so we drop the table
completely, and then re-add it, which should result in an empty
suppressions table with all expected constraints.

We've also renamed the `email_address` column to `email` to match our
`users` & `members` tables
This commit is contained in:
Fabien 'egg' O'Carroll 2023-01-04 17:26:57 +07:00 committed by GitHub
parent 819d0d884c
commit 50e99e013c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 7 deletions

View File

@ -0,0 +1,14 @@
const {addTable} = require('../../utils');
const migration = 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}
});
module.exports = {
up: migration.down,
down: migration.up
};

View File

@ -0,0 +1,9 @@
const {addTable} = require('../../utils');
module.exports = addTable('suppressions', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
email: {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}
});

View File

@ -955,7 +955,7 @@ module.exports = {
},
suppressions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
email_address: {type: 'string', maxlength: 191, nullable: false, unique: true, validations: {isEmail: true}},
email: {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',

View File

@ -35,7 +35,7 @@ class MailgunEmailSuppressionList extends AbstractEmailSuppressionList {
try {
await this.Suppression.destroy({
destroyBy: {
email_address: email
email: email
}
});
} catch (err) {
@ -49,7 +49,7 @@ class MailgunEmailSuppressionList extends AbstractEmailSuppressionList {
async getSuppressionData(email) {
try {
const model = await this.Suppression.findOne({
email_address: email
email: email
});
if (!model) {
@ -73,11 +73,11 @@ class MailgunEmailSuppressionList extends AbstractEmailSuppressionList {
try {
const collection = await this.Suppression.findAll({
filter: `email_address:[${emails.join(',')}]`
filter: `email:[${emails.join(',')}]`
});
return emails.map((email) => {
const model = collection.models.find(m => m.get('email_address') === email);
const model = collection.models.find(m => m.get('email') === email);
if (!model) {
return new EmailSuppressionData(false);
@ -106,7 +106,7 @@ class MailgunEmailSuppressionList extends AbstractEmailSuppressionList {
}
}
await this.Suppression.add({
email_address: event.email,
email: event.email,
email_id: event.emailId,
reason: reason,
created_at: event.timestamp

View File

@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '7e561ad3b6eec1b9188f54ad46b04f40';
const currentSchemaHash = 'a3df9e11b3db1c8afdfb87c7a206b53b';
const currentFixturesHash = 'dcb7ba7c66b4b98d6c26a722985e756a';
const currentSettingsHash = '9acce72858e75420b831297718595bbd';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';