Added subscribed column to members table

no issue

- Needed for unsubscribe functionality
This commit is contained in:
Nazar Gargol 2019-11-05 15:49:40 +07:00 committed by Fabien O'Carroll
parent b2f86315c0
commit 1ef015da10
3 changed files with 46 additions and 1 deletions

View File

@ -0,0 +1,44 @@
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({
table: 'members',
column: 'subscribed',
dbIsInCorrectState(columnExists) {
return columnExists === true;
},
operation: commands.addColumn,
operationVerb: 'Adding'
});
module.exports.down = createColumnMigration({
table: 'members',
column: 'subscribed',
dbIsInCorrectState(columnExists) {
return columnExists === false;
},
operation: commands.dropColumn,
operationVerb: 'Removing'
});
module.exports.config = {
transaction: true
};

View File

@ -326,6 +326,7 @@ module.exports = {
email: {type: 'string', maxlength: 191, nullable: false, unique: true, validations: {isEmail: true}},
name: {type: 'string', maxlength: 191, nullable: true},
note: {type: 'string', maxlength: 2000, nullable: true},
subscribed: {type: 'bool', nullable: true, defaultTo: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},

View File

@ -19,7 +19,7 @@ var should = require('should'),
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = 'b76727048bd7851cb9fbfbefc9b00745';
const currentSchemaHash = 'd7af2f707b0221871d27d9387e0de2e2';
const currentFixturesHash = '84005b6e8f62231b6fd0fc261ce893db';
// If this test is failing, then it is likely a change has been made that requires a DB version bump,