2016-10-10 15:27:31 +03:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
commands = require('../../schema').commands,
|
2017-12-11 22:27:09 +03:00
|
|
|
logging = require('../../../lib/common/logging'),
|
2016-10-10 15:27:31 +03:00
|
|
|
schema = require('../../schema').tables,
|
|
|
|
schemaTables = Object.keys(schema);
|
|
|
|
|
2017-12-05 11:14:55 +03:00
|
|
|
module.exports.up = function createTables(options) {
|
|
|
|
var connection = options.connection;
|
2016-10-10 15:27:31 +03:00
|
|
|
|
|
|
|
return Promise.mapSeries(schemaTables, function createTable(table) {
|
|
|
|
logging.info('Creating table: ' + table);
|
2017-12-05 11:14:55 +03:00
|
|
|
return commands.createTable(table, connection);
|
2016-10-10 15:27:31 +03:00
|
|
|
});
|
|
|
|
};
|
2017-12-05 11:14:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
@TODO: This works, but is very dangerous in the current state of the knex-migrator v3.
|
|
|
|
@TODO: Enable if knex-migrator v3 is stable.
|
|
|
|
module.exports.down = function dropTables(options) {
|
|
|
|
var connection = options.connection;
|
|
|
|
|
|
|
|
// Reference between tables!
|
|
|
|
schemaTables.reverse();
|
|
|
|
return Promise.mapSeries(schemaTables, function dropTable(table) {
|
|
|
|
logging.info('Drop table: ' + table);
|
|
|
|
return commands.deleteTable(table, connection);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
*/
|