-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate-db.js
More file actions
executable file
·41 lines (32 loc) · 915 Bytes
/
Copy pathmigrate-db.js
File metadata and controls
executable file
·41 lines (32 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
module.exports = function (params) {
require('config/init')();
const config = require('config/config');
const log = require('config/log')(module);
const DBMigrate = require('db-migrate');
log.info('Running migration...');
const callback = (err) => process.exit(err ? 1 : 0);
const intCallback = (err) => {
if (err) {
log.error(err);
log.error(err.originalErr);
return callback(err);
}
console.log('Migration completed');
callback();
};
const dbMigrate = DBMigrate.getInstance(true, {
config: {
dev: config.mongo
}
});
const isUp = (process.argv[4] !== 'down');
const count = process.argv.length > 5 ? process.argv[5] : undefined;
if (isUp) {
console.log('migrating up');
dbMigrate.up(count, null, intCallback);
} else {
console.log('migrating down');
dbMigrate.down(count, null, intCallback);
}
};