0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/core/server/data/migrations/init/1-create-tables.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

const Promise = require('bluebird');
const commands = require('../../schema').commands;
const schema = require('../../schema').tables;
const logging = require('@tryghost/logging');
const schemaTables = Object.keys(schema);
module.exports.up = async (options) => {
const connection = options.connection;
const existingTables = await commands.getTables(connection);
const missingTables = schemaTables.filter(t => !existingTables.includes(t));
await Promise.mapSeries(missingTables, async (table) => {
logging.info('Creating table: ' + table);
await commands.createTable(table, connection);
});
};
/**
@TODO: This works, but is very dangerous in the current state of the knex-migrator v3.
@TODO: Decide if we should enable or delete this
module.exports.down = async (options) => {
var connection = options.connection;
// Reference between tables!
schemaTables.reverse();
await Promise.mapSeries(schemaTables, async (table) => {
logging.info('Drop table: ' + table);
await commands.deleteTable(table, connection);
});
};
*/