Skip to content

Commit

Permalink
🐛 fix backup database (#7898)
Browse files Browse the repository at this point in the history
refs #7489

The require path for the db backup was wrong. The before hook could not execute db backup.
Furthermore, i have replaced the logging in the backup script.
  • Loading branch information
kirrg001 committed Jan 25, 2017
1 parent ee3033c commit 0424c66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
17 changes: 6 additions & 11 deletions core/server/data/db/backup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// # Backup Database
// Provides for backing up the database before making potentially destructive changes
var _ = require('lodash'),
fs = require('fs'),
var fs = require('fs'),
path = require('path'),
Promise = require('bluebird'),
config = require('../../config'),
exporter = require('../export'),
logging = require('../../logging'),
utils = require('../../utils'),
exporter = require('../export'),

writeExportFile,
backup;
Expand All @@ -20,15 +20,10 @@ writeExportFile = function writeExportFile(exportResult) {
/**
* ## Backup
* does an export, and stores this in a local file
*
* @param {{info: logger.info, warn: logger.warn}} [logger]
* @returns {Promise<*>}
*/
backup = function backup(logger) {
// If we get passed a function, use it to output notices, else don't do anything
logger = logger && _.isFunction(logger.info) ? logger : {info: _.noop};

logger.info('Creating database backup');
backup = function backup() {
logging.info('Creating database backup');

var props = {
data: exporter.doExport(),
Expand All @@ -38,7 +33,7 @@ backup = function backup(logger) {
return Promise.props(props)
.then(writeExportFile)
.then(function successMessage(filename) {
logger.info('Database backup written to: ' + filename);
logging.info('Database backup written to: ' + filename);
});
};

Expand Down
2 changes: 1 addition & 1 deletion core/server/data/migrations/hooks/migrate/before.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var backup = require('../../../schema/backup'),
var backup = require('../../../db/backup'),
models = require('../../../../models');

module.exports = function before(options) {
Expand Down
15 changes: 0 additions & 15 deletions core/test/unit/migration_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,5 @@ describe('Migrations', function () {
done();
}).catch(done);
});

it('should fall back to console.log if no logger provided', function (done) {
var noopStub = sandbox.stub(_, 'noop');

backupDatabase().then(function () {
exportStub.calledOnce.should.be.true();
filenameStub.calledOnce.should.be.true();
fsStub.calledOnce.should.be.true();
noopStub.calledTwice.should.be.true();
// restore early so we get the test output
noopStub.restore();

done();
}).catch(done);
});
});
});

0 comments on commit 0424c66

Please sign in to comment.