diff --git a/core/server/data/migrations/versions/3.1/1-add-send-email-when-published-to-posts.js b/core/server/data/migrations/versions/3.1/1-add-send-email-when-published-to-posts.js index c8ac5f6d14..6e54de0a2a 100644 --- a/core/server/data/migrations/versions/3.1/1-add-send-email-when-published-to-posts.js +++ b/core/server/data/migrations/versions/3.1/1-add-send-email-when-published-to-posts.js @@ -1,25 +1,6 @@ -const common = require('../../../../lib/common'); const commands = require('../../../schema').commands; -const createLog = type => msg => common.logging[type](msg); - -function createColumnMigration({table, column, dbIsInCorrectState, operation, operationVerb}) { - return function columnMigrations({transacting}) { - return transacting.schema.hasColumn(table, column) - .then(dbIsInCorrectState) - .then((isInCorrectState) => { - const log = createLog(isInCorrectState ? 'warn' : 'info'); - - log(`${operationVerb} ${table}.${column}`); - - if (!isInCorrectState) { - return operation(table, column, transacting); - } - }); - }; -} - -module.exports.up = createColumnMigration({ +module.exports.up = commands.createColumnMigration({ table: 'posts', column: 'send_email_when_published', dbIsInCorrectState(columnExists) { @@ -29,7 +10,7 @@ module.exports.up = createColumnMigration({ operationVerb: 'Adding' }); -module.exports.down = createColumnMigration({ +module.exports.down = commands.createColumnMigration({ table: 'posts', column: 'send_email_when_published', dbIsInCorrectState(columnExists) { diff --git a/core/server/data/migrations/versions/3.1/2-add-email-subject-to-posts-meta.js b/core/server/data/migrations/versions/3.1/2-add-email-subject-to-posts-meta.js new file mode 100644 index 0000000000..cb6f3c76f3 --- /dev/null +++ b/core/server/data/migrations/versions/3.1/2-add-email-subject-to-posts-meta.js @@ -0,0 +1,25 @@ +const commands = require('../../../schema').commands; + +module.exports.up = commands.createColumnMigration({ + table: 'posts_meta', + column: 'email_subject', + dbIsInCorrectState(columnExists) { + return columnExists === true; + }, + operation: commands.addColumn, + operationVerb: 'Adding' +}); + +module.exports.down = commands.createColumnMigration({ + table: 'posts_meta', + column: 'email_subject', + dbIsInCorrectState(columnExists) { + return columnExists === false; + }, + operation: commands.dropColumn, + operationVerb: 'Removing' +}); + +module.exports.config = { + transaction: true +};