2014-06-01 03:53:21 +04:00
|
|
|
var _ = require('lodash'),
|
|
|
|
when = require('when'),
|
|
|
|
versioning = require('../versioning'),
|
|
|
|
knex = require('../../models/base').knex,
|
2014-06-10 00:37:44 +04:00
|
|
|
utils = require('../utils'),
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-11-24 18:29:36 +04:00
|
|
|
excludedTables = ['sessions'],
|
2013-09-15 20:04:42 +04:00
|
|
|
exporter;
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-09-15 20:04:42 +04:00
|
|
|
exporter = function () {
|
2014-06-10 00:37:44 +04:00
|
|
|
return when.join(versioning.getDatabaseVersion(), utils.getTables()).then(function (results) {
|
2013-09-15 20:04:42 +04:00
|
|
|
var version = results[0],
|
|
|
|
tables = results[1],
|
|
|
|
selectOps = _.map(tables, function (name) {
|
2013-11-24 18:29:36 +04:00
|
|
|
if (excludedTables.indexOf(name) < 0) {
|
|
|
|
return knex(name).select();
|
|
|
|
}
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
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) {
|
2014-06-10 00:37:44 +04:00
|
|
|
console.log('Error exporting data: ' + err);
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
};
|
2013-09-15 20:04:42 +04:00
|
|
|
|
2014-06-10 00:37:44 +04:00
|
|
|
module.exports = exporter;
|