|
1 |
| -var Promise = require('bluebird'), |
| 1 | +var Promise = require('bluebird'), |
2 | 2 | commands = require('../../schema').commands,
|
3 |
| - db = require('../../db'), |
| 3 | + table = 'clients', |
| 4 | + columns = ['redirection_uri', 'logo', 'status', 'type', 'description']; |
4 | 5 |
|
5 |
| - table = 'clients', |
6 |
| - columns = ['redirection_uri', 'logo', 'status', 'type', 'description']; |
| 6 | +module.exports = function addManyColumnsToClients(options, logger) { |
| 7 | + var transaction = options.transacting; |
| 8 | + |
| 9 | + return transaction.schema.hasTable(table) |
| 10 | + .then(function (exists) { |
| 11 | + if (!exists) { |
| 12 | + return Promise.reject(new Error('Table does not exist!')); |
| 13 | + } |
7 | 14 |
|
8 |
| -module.exports = function addManyColumnsToClients(logger) { |
9 |
| - return db.knex.schema.hasTable(table).then(function (exists) { |
10 |
| - if (exists) { |
11 | 15 | return Promise.mapSeries(columns, function (column) {
|
12 | 16 | var message = 'Adding column: ' + table + '.' + column;
|
13 |
| - return db.knex.schema.hasColumn(table, column).then(function (exists) { |
14 |
| - if (!exists) { |
15 |
| - logger.info(message); |
16 |
| - return commands.addColumn(table, column); |
17 |
| - } else { |
18 |
| - logger.warn(message); |
19 |
| - } |
20 |
| - }); |
| 17 | + |
| 18 | + return transaction.schema.hasColumn(table, column) |
| 19 | + .then(function (exists) { |
| 20 | + if (!exists) { |
| 21 | + logger.info(message); |
| 22 | + return commands.addColumn(table, column, transaction); |
| 23 | + } else { |
| 24 | + logger.warn(message); |
| 25 | + } |
| 26 | + }); |
21 | 27 | });
|
22 |
| - } else { |
23 |
| - // @TODO: this should probably be an error |
24 |
| - logger.warn('Adding columns to table: ' + table); |
25 |
| - } |
26 |
| - }); |
| 28 | + }); |
27 | 29 | };
|
0 commit comments