452ac4283ba71efa0b5942269682ead45f30bed8
[oweals/peertube.git] / server / models / application.js
1 const mongoose = require('mongoose')
2
3 // ---------------------------------------------------------------------------
4
5 const ApplicationSchema = mongoose.Schema({
6   mongoSchemaVersion: {
7     type: Number,
8     default: 0
9   }
10 })
11
12 ApplicationSchema.statics = {
13   loadMongoSchemaVersion,
14   updateMongoSchemaVersion
15 }
16
17 mongoose.model('Application', ApplicationSchema)
18
19 // ---------------------------------------------------------------------------
20
21 function loadMongoSchemaVersion (callback) {
22   return this.findOne({}, { mongoSchemaVersion: 1 }, function (err, data) {
23     const version = data ? data.mongoSchemaVersion : 0
24
25     return callback(err, version)
26   })
27 }
28
29 function updateMongoSchemaVersion (newVersion, callback) {
30   return this.update({}, { mongoSchemaVersion: newVersion }, callback)
31 }