forked from SAP-archive/cloud-cf-lets-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migroose.js
34 lines (29 loc) · 944 Bytes
/
migroose.js
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
'use strict';
var mongoose = require('mongoose'),
settings = require('./app/config'),
migroose = require('migroose'),
Runner = require('migroose-cli/cli/runner/index');
var MigrationModel = migroose.MigrationModel;
module.exports = {
connect: function(cb){
mongoose.connect(settings.database.uri, function(err){
if (err) { throw err; }
cb();
});
},
needsMigration: function(cb) {
var runner = new Runner(process.cwd(), 'migrootions');
var migrations = runner.getMigrations();
var lastMigration = migrations.slice(migrations.length - 1)[0];
MigrationModel.findOne({migrationId: lastMigration.migrationId}, function(err, model) {
if (err) {
return cb(err);
}
if (model) {
cb(null, false);
} else {
cb(null, true);
}
});
}
};