Skip to content

Commit

Permalink
Added migrations for email settings
Browse files Browse the repository at this point in the history
no issue
  • Loading branch information
rishabhgrg committed Nov 4, 2019
1 parent f2f9073 commit 2ac2975
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
@@ -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) {
Expand All @@ -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) {
Expand Down
@@ -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
};

0 comments on commit 2ac2975

Please sign in to comment.