Ghost/core/server/data/migration/populate.js
Hannah Wolfe 84f387785a Migration messaging improvements
refs #6301

- fix messages that joined with comma and therefore missed outputting version no
- change `logInfo` to `logger` that has both an info and a warn method
- add new warn method to errors
- add a warn message everytime a migration (data or fixture) gets skipped over
- update logger everywhere, including tests
- update tests to check logger.warn gets called
2016-03-22 09:59:22 +00:00

41 lines
1.2 KiB
JavaScript

// # Populate
// Create a brand new database for a new install of ghost
var Promise = require('bluebird'),
commands = require('../schema').commands,
fixtures = require('./fixtures'),
schema = require('../schema').tables,
schemaTables = Object.keys(schema),
populate;
/**
* ## Populate
* Uses the schema to determine table structures, and automatically creates each table in order
* TODO: use this directly in tests, so migration.init() can forget about tablesOnly as an option
*
* @param {{info: logger.info, warn: logger.warn}} logger
* @param {Boolean} [tablesOnly] - used by tests
* @returns {Promise<*>}
*/
populate = function populate(logger, tablesOnly) {
logger.info('Creating tables...');
var tableSequence = Promise.mapSeries(schemaTables, function createTable(table) {
logger.info('Creating table: ' + table);
return commands.createTable(table);
});
if (tablesOnly) {
return tableSequence;
}
return tableSequence.then(function () {
// Load the fixtures
return fixtures.populate(logger);
}).then(function () {
return fixtures.ensureDefaultSettings(logger);
});
};
module.exports = populate;