2020-04-29 16:44:27 +01:00
|
|
|
const Promise = require('bluebird');
|
|
|
|
const commands = require('../../schema').commands;
|
|
|
|
const schema = require('../../schema').tables;
|
2021-06-15 15:36:27 +01:00
|
|
|
const logging = require('@tryghost/logging');
|
2020-04-29 16:44:27 +01:00
|
|
|
const schemaTables = Object.keys(schema);
|
2016-10-10 14:27:31 +02:00
|
|
|
|
2021-10-21 11:19:59 +01:00
|
|
|
module.exports.up = async (options) => {
|
2020-04-29 16:44:27 +01:00
|
|
|
const connection = options.connection;
|
2016-10-10 14:27:31 +02:00
|
|
|
|
2022-02-18 10:51:53 +01:00
|
|
|
const existingTables = await commands.getTables(connection);
|
|
|
|
const missingTables = schemaTables.filter(t => !existingTables.includes(t));
|
|
|
|
|
|
|
|
await Promise.mapSeries(missingTables, async (table) => {
|
2020-05-25 03:48:50 -05:00
|
|
|
logging.info('Creating table: ' + table);
|
2021-10-21 11:19:59 +01:00
|
|
|
await commands.createTable(table, connection);
|
2016-10-10 14:27:31 +02:00
|
|
|
});
|
|
|
|
};
|
2017-12-05 09:14:55 +01:00
|
|
|
|
2017-12-11 22:47:46 +01:00
|
|
|
/**
|
|
|
|
@TODO: This works, but is very dangerous in the current state of the knex-migrator v3.
|
2021-10-21 11:19:59 +01:00
|
|
|
@TODO: Decide if we should enable or delete this
|
|
|
|
module.exports.down = async (options) => {
|
2017-12-11 22:47:46 +01:00
|
|
|
var connection = options.connection;
|
2017-12-05 09:14:55 +01:00
|
|
|
|
2017-12-11 22:47:46 +01:00
|
|
|
// Reference between tables!
|
|
|
|
schemaTables.reverse();
|
2021-10-21 11:19:59 +01:00
|
|
|
await Promise.mapSeries(schemaTables, async (table) => {
|
2020-05-25 03:48:50 -05:00
|
|
|
logging.info('Drop table: ' + table);
|
2021-10-21 11:19:59 +01:00
|
|
|
await commands.deleteTable(table, connection);
|
2017-12-11 22:47:46 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
*/
|