mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-17 05:21:36 +03:00
6e1bd2838e
closes #6972, #6574 - run each database version as top level transaction - run migrations in correct order
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
var Promise = require('bluebird'),
|
|
commands = require('../../schema').commands,
|
|
table = 'clients',
|
|
columns = ['redirection_uri', 'logo', 'status', 'type', 'description'];
|
|
|
|
module.exports = function addManyColumnsToClients(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);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
};
|