diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-09-26 22:36:36 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-09-26 22:39:58 +0200 |
commit | 00d6b0dda4b1964ab11127851c0fc7106cc0f912 (patch) | |
tree | 3759ff8c8724f85f2554c28edf5bcf58a60085cf /server/models/application.js | |
parent | 44c5275e1bdd1d4b4c23f7c423034e4293c927b3 (diff) | |
download | PeerTube-00d6b0dda4b1964ab11127851c0fc7106cc0f912.tar.gz PeerTube-00d6b0dda4b1964ab11127851c0fc7106cc0f912.tar.zst PeerTube-00d6b0dda4b1964ab11127851c0fc7106cc0f912.zip |
Add migration (for db, folders...) mechanism
Diffstat (limited to 'server/models/application.js')
-rw-r--r-- | server/models/application.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server/models/application.js b/server/models/application.js new file mode 100644 index 000000000..8185f0915 --- /dev/null +++ b/server/models/application.js | |||
@@ -0,0 +1,31 @@ | |||
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: loadMongoSchemaVersion, | ||
14 | updateMongoSchemaVersion: 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 | } | ||