2016-09-26 22:36:36 +02:00
|
|
|
const mongoose = require('mongoose')
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const ApplicationSchema = mongoose.Schema({
|
|
|
|
mongoSchemaVersion: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
ApplicationSchema.statics = {
|
2016-10-02 12:19:02 +02:00
|
|
|
loadMongoSchemaVersion,
|
|
|
|
updateMongoSchemaVersion
|
2016-09-26 22:36:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mongoose.model('Application', ApplicationSchema)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function loadMongoSchemaVersion (callback) {
|
|
|
|
return this.findOne({}, { mongoSchemaVersion: 1 }, function (err, data) {
|
|
|
|
const version = data ? data.mongoSchemaVersion : 0
|
|
|
|
|
|
|
|
return callback(err, version)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateMongoSchemaVersion (newVersion, callback) {
|
|
|
|
return this.update({}, { mongoSchemaVersion: newVersion }, callback)
|
|
|
|
}
|