mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
07df9911ce
Closes #847 - Added logic to export database to the `core\server\data\` folder prior to beginning a migration. - Factored out versioning logic from migration to prevent circular references
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
var _ = require('lodash'),
|
|
when = require('when'),
|
|
versioning = require('../versioning'),
|
|
knex = require('../../models/base').knex,
|
|
schema = require('../schema').tables,
|
|
|
|
excludedTables = ['sessions'],
|
|
exporter;
|
|
|
|
exporter = function () {
|
|
var tablesToExport = _.keys(schema);
|
|
|
|
return when.join(versioning.getDatabaseVersion(), tablesToExport).then(function (results) {
|
|
var version = results[0],
|
|
tables = results[1],
|
|
selectOps = _.map(tables, function (name) {
|
|
if (excludedTables.indexOf(name) < 0) {
|
|
return knex(name).select();
|
|
}
|
|
});
|
|
|
|
return when.all(selectOps).then(function (tableData) {
|
|
var exportData = {
|
|
meta: {
|
|
exported_on: new Date().getTime(),
|
|
version: version
|
|
},
|
|
data: {
|
|
// Filled below
|
|
}
|
|
};
|
|
|
|
_.each(tables, function (name, i) {
|
|
exportData.data[name] = tableData[i];
|
|
});
|
|
|
|
return when.resolve(exportData);
|
|
}, function (err) {
|
|
console.log("Error exporting data: " + err);
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports = exporter; |