2020-04-29 18:44:27 +03:00
|
|
|
const Promise = require('bluebird');
|
|
|
|
const commands = require('../../schema').commands;
|
|
|
|
const schema = require('../../schema').tables;
|
2021-06-15 17:36:27 +03:00
|
|
|
const logging = require('@tryghost/logging');
|
2020-04-29 18:44:27 +03:00
|
|
|
const schemaTables = Object.keys(schema);
|
2016-10-10 15:27:31 +03:00
|
|
|
|
2017-12-05 11:14:55 +03:00
|
|
|
module.exports.up = function createTables(options) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const connection = options.connection;
|
2016-10-10 15:27:31 +03:00
|
|
|
|
|
|
|
return Promise.mapSeries(schemaTables, function createTable(table) {
|
2020-05-25 11:48:50 +03:00
|
|
|
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
|
|
|
|
2017-12-12 00:47:46 +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;
|
2017-12-05 11:14:55 +03:00
|
|
|
|
2017-12-12 00:47:46 +03:00
|
|
|
// Reference between tables!
|
|
|
|
schemaTables.reverse();
|
|
|
|
return Promise.mapSeries(schemaTables, function dropTable(table) {
|
2020-05-25 11:48:50 +03:00
|
|
|
logging.info('Drop table: ' + table);
|
2017-12-12 00:47:46 +03:00
|
|
|
return commands.deleteTable(table, connection);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
*/
|