Ghost/core/server/data/export/index.js
Sebastian Gierlinger 3f2258e95b Replace cookieSession with session
- changed cookieSession to session
- added session.regenerate for login and logout
- added bookshelf session store
- added session table to database
- added import for databaseVersion 001
- added grunt task test-api
- cleanup of gruntfile to start express when needed only
- moved api tests to functional tests
2013-11-24 15:29:36 +01:00

44 lines
1.3 KiB
JavaScript

var when = require('when'),
_ = require('underscore'),
migration = require('../migration'),
knex = require('../../models/base').knex,
schema = require('../schema'),
excludedTables = ['sessions'],
exporter;
exporter = function () {
var tablesToExport = _.keys(schema);
return when.join(migration.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;