1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add migration (for db, folders...) mechanism

This commit is contained in:
Chocobozzz 2016-09-26 22:36:36 +02:00
parent 44c5275e1b
commit 00d6b0dda4
8 changed files with 174 additions and 21 deletions

View file

@ -0,0 +1,31 @@
const mongoose = require('mongoose')
// ---------------------------------------------------------------------------
const ApplicationSchema = mongoose.Schema({
mongoSchemaVersion: {
type: Number,
default: 0
}
})
ApplicationSchema.statics = {
loadMongoSchemaVersion: loadMongoSchemaVersion,
updateMongoSchemaVersion: 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)
}