Added migration to remove surrounding <> in email_batches.provider_id (#12673)

refs https://github.com/TryGhost/Team/issues/221#issuecomment-759105424

- Mailgun responds to an email send with a provider id in the format `<x@y.com>` but everywhere else it's used in their API it uses the format `x@y.com`
- updates email batch save to strip the brackets, and migration removes brackets from existing records so we no longer have to add special handling for the stored id any time we use it
This commit is contained in:
Kevin Ansfield 2021-02-23 08:48:21 +00:00 committed by GitHub
parent 94f5aa45e8
commit 08e1268aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

View File

@ -0,0 +1,8 @@
const logging = require('../../../../../shared/logging');
const {createIrreversibleMigration} = require('../../utils');
module.exports = createIrreversibleMigration(async (knex) => {
logging.info('Sanitizing provider_id values in email_batches');
await knex.raw('UPDATE email_batches SET provider_id = REPLACE(REPLACE(provider_id, "<", ""), ">", "")');
});

View File

@ -168,7 +168,7 @@ module.exports = {
// update batch success status
return await emailBatchModel.save({
status: 'submitted',
provider_id: sendResponse.id
provider_id: sendResponse.id.trim().replace(/^<|>$/g, '')
}, Object.assign({}, knexOptions, {patch: true}));
} catch (error) {
// update batch failed status

View File

@ -114,11 +114,7 @@ class EmailAnalyticsMailgunProvider {
}
normalizeEvent(event) {
// TODO: clean up the <> surrounding email_batches.provider_id values
let providerId = event.message && event.message.headers && event.message.headers['message-id'];
if (providerId) {
providerId = `<${providerId}>`;
}
return {
type: event.event,

View File

@ -478,8 +478,7 @@ DataGenerator.Content = {
{
id: ObjectId.generate(),
email_id: null, // emails[0] relation added later
// TODO: cleanup <> in provider_id
provider_id: '<email1@testing.mailgun.net>',
provider_id: 'email1@testing.mailgun.net',
status: 'submitted'
}
],