2016-03-14 17:39:00 +00:00
|
|
|
var commands = require('../../schema').commands,
|
|
|
|
db = require('../../db'),
|
|
|
|
|
|
|
|
table = 'clients',
|
2016-03-21 12:44:23 +00:00
|
|
|
column = 'secret',
|
|
|
|
message = 'Dropping unique on: ' + table + '.' + column;
|
2016-03-14 17:39:00 +00:00
|
|
|
|
2016-03-21 12:44:23 +00:00
|
|
|
module.exports = function dropUniqueOnClientsSecret(logger) {
|
2016-03-14 17:39:00 +00:00
|
|
|
return db.knex.schema.hasTable(table).then(function (exists) {
|
|
|
|
if (exists) {
|
|
|
|
return commands.getIndexes(table).then(function (indexes) {
|
|
|
|
if (indexes.indexOf(table + '_' + column + '_unique') > -1) {
|
2016-03-21 12:44:23 +00:00
|
|
|
logger.info(message);
|
2016-03-14 17:39:00 +00:00
|
|
|
return commands.dropUnique(table, column);
|
2016-03-21 12:44:23 +00:00
|
|
|
} else {
|
|
|
|
logger.warn(message);
|
2016-03-14 17:39:00 +00:00
|
|
|
}
|
|
|
|
});
|
2016-03-21 12:44:23 +00:00
|
|
|
} else {
|
|
|
|
// @TODO: this should probably be an error
|
|
|
|
logger.warn(message);
|
2016-03-14 17:39:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|