2016-07-14 13:59:42 +03:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
commands = require('../../schema').commands,
|
|
|
|
table = 'users',
|
|
|
|
column = 'tour',
|
|
|
|
message = 'Adding column: ' + table + '.' + column;
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-07-14 13:59:42 +03:00
|
|
|
module.exports = function addTourColumnToUsers(options, logger) {
|
|
|
|
var transaction = options.transacting;
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-07-14 13:59:42 +03:00
|
|
|
return transaction.schema.hasTable(table)
|
|
|
|
.then(function (exists) {
|
|
|
|
if (!exists) {
|
|
|
|
return Promise.reject(new Error('Table does not exist!'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return transaction.schema.hasColumn(table, column);
|
|
|
|
})
|
|
|
|
.then(function (exists) {
|
|
|
|
if (!exists) {
|
|
|
|
logger.info(message);
|
|
|
|
return commands.addColumn(table, column, transaction);
|
|
|
|
} else {
|
|
|
|
logger.warn(message);
|
|
|
|
}
|
|
|
|
});
|
2016-03-14 20:39:00 +03:00
|
|
|
};
|