aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/application.js
blob: 452ac4283ba71efa0b5942269682ead45f30bed8 (plain) (blame)
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
const mongoose = require('mongoose')

// ---------------------------------------------------------------------------

const ApplicationSchema = mongoose.Schema({
  mongoSchemaVersion: {
    type: Number,
    default: 0
  }
})

ApplicationSchema.statics = {
  loadMongoSchemaVersion,
  updateMongoSchemaVersion
}

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)
}