mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
748c664b78
closes #6976 - add maintenance mode when running migrations - refactor update/populate migrations
50 lines
1.3 KiB
JavaScript
50 lines
1.3 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'),
|
|
errors = require('../../errors'),
|
|
schema = require('../schema').tables,
|
|
schemaTables = Object.keys(schema),
|
|
populate, logger;
|
|
|
|
// @TODO: remove me asap!
|
|
logger = {
|
|
info: function info(message) {
|
|
errors.logComponentInfo('Migrations', message);
|
|
},
|
|
warn: function warn(message) {
|
|
errors.logComponentWarn('Skipping Migrations', message);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* ## Populate
|
|
* Uses the schema to determine table structures, and automatically creates each table in order
|
|
*/
|
|
populate = function populate(options) {
|
|
options = options || {};
|
|
|
|
var tablesOnly = options.tablesOnly,
|
|
modelOptions = {
|
|
context: {
|
|
internal: true
|
|
}
|
|
},
|
|
tableSequence = Promise.mapSeries(schemaTables, function createTable(table) {
|
|
logger.info('Creating table: ' + table);
|
|
return commands.createTable(table);
|
|
});
|
|
|
|
logger.info('Creating tables...');
|
|
|
|
if (tablesOnly) {
|
|
return tableSequence;
|
|
}
|
|
|
|
return tableSequence.then(function () {
|
|
return fixtures.populate(logger, modelOptions);
|
|
});
|
|
};
|
|
|
|
module.exports = populate;
|