mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-11 09:53:32 +03:00
d9c45b4967
Closes #2927 -refactor exporter to export tables that exist in the database instead of keying off of schema.js -move some shared database utility functions into their own module
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
var _ = require('lodash'),
|
|
when = require('when'),
|
|
versioning = require('../versioning'),
|
|
knex = require('../../models/base').knex,
|
|
utils = require('../utils'),
|
|
|
|
excludedTables = ['sessions'],
|
|
exporter;
|
|
|
|
exporter = function () {
|
|
return when.join(versioning.getDatabaseVersion(), utils.getTables()).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;
|