2014-06-01 03:53:21 +04:00
|
|
|
var _ = require('lodash'),
|
|
|
|
when = require('when'),
|
|
|
|
versioning = require('../versioning'),
|
2014-05-16 06:29:42 +04:00
|
|
|
config = require('../../config'),
|
2014-06-10 00:37:44 +04:00
|
|
|
utils = require('../utils'),
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2014-07-14 16:29:45 +04:00
|
|
|
excludedTables = [],
|
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) {
|
2014-05-16 06:29:42 +04:00
|
|
|
return config().database.knex(name).select();
|
2013-11-24 18:29:36 +04:00
|
|
|
}
|
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);
|
2014-06-10 20:06:08 +04:00
|
|
|
}).catch(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;
|