0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/core/server/data/migration/005/02-add-visibility-column-to-key-tables.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
992 B
JavaScript

var Promise = require('bluebird'),
commands = require('../../schema').commands,
tables = ['posts', 'tags', 'users'],
column = 'visibility';
module.exports = function addVisibilityColumnToKeyTables(options, logger) {
var transaction = options.transacting;
return Promise.mapSeries(tables, function (table) {
var message = 'Adding column: ' + table + '.' + column;
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);
}
});
});
};