Ghost/core/server/data/migration/005/04-add-social-media-columns-to-users.js
Katharina Irrgang 6e1bd2838e improvement: migrations (#7000)
closes #6972, #6574

- run each database version as top level transaction
- run migrations in correct order
2016-07-14 11:59:42 +01:00

29 lines
999 B
JavaScript

var Promise = require('bluebird'),
commands = require('../../schema').commands,
table = 'users',
columns = ['facebook', 'twitter'];
module.exports = function addSocialMediaColumnsToUsers(options, logger) {
var transaction = options.transacting;
return transaction.schema.hasTable(table)
.then(function (exists) {
if (!exists) {
return Promise.reject(new Error('Table does not exist!'));
}
return Promise.mapSeries(columns, function (column) {
var message = 'Adding column: ' + table + '.' + column;
return transaction.schema.hasColumn(table, column).then(function (exists) {
if (!exists) {
logger.info(message);
return commands.addColumn(table, column, transaction);
} else {
logger.warn(message);
}
});
});
});
};