mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
41 lines
1.2 KiB
JavaScript
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 {Function} logInfo
|
||
|
* @param {Boolean} [tablesOnly] - used by tests
|
||
|
* @returns {Promise<*>}
|
||
|
*/
|
||
|
populate = function populate(logInfo, tablesOnly) {
|
||
|
logInfo('Creating tables...');
|
||
|
|
||
|
var tableSequence = Promise.mapSeries(schemaTables, function createTable(table) {
|
||
|
logInfo('Creating table: ' + table);
|
||
|
return commands.createTable(table);
|
||
|
});
|
||
|
|
||
|
if (tablesOnly) {
|
||
|
return tableSequence;
|
||
|
}
|
||
|
|
||
|
return tableSequence.then(function () {
|
||
|
// Load the fixtures
|
||
|
return fixtures.populate(logInfo);
|
||
|
}).then(function () {
|
||
|
return fixtures.ensureDefaultSettings(logInfo);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports = populate;
|