Ghost/core/server/data/migration/004/05-drop-unique-on-clients-secret.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

27 lines
882 B
JavaScript

var Promise = require('bluebird'),
commands = require('../../schema').commands,
table = 'clients',
column = 'secret',
message = 'Dropping unique on: ' + table + '.' + column;
module.exports = function dropUniqueOnClientsSecret(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 commands.getIndexes(table, transaction);
})
.then(function (indexes) {
if (indexes.indexOf(table + '_' + column + '_unique') > -1) {
logger.info(message);
return commands.dropUnique(table, column, transaction);
} else {
logger.warn(message);
}
});
};