mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs #6301 - changes createTable to use createTableIfNotExists, this is consistent with deletion - splits out backup, reset, update and populate functions from migration/index into their own files - moves the wrapped function for populatingDefaultSettings to fixtures.ensureDefaultSettings - moves `modelOptions` down to the fixture files that actually use it - adds test coverage for backup, reset and populate, but not for update as that needs refactoring
40 lines
1.2 KiB
JavaScript
40 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;
|