aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/application.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-11 21:50:51 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-19 21:22:28 +0100
commitfeb4bdfd9b46e87aadfa7c0d5338cde887d1f58c (patch)
tree2abc9fbc9569760e218fd52835850b757344b420 /server/models/application.js
parent108626609eda75e4ecc0a83a650a4d53c46220e0 (diff)
downloadPeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.tar.gz
PeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.tar.zst
PeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.zip
First version with PostgreSQL
Diffstat (limited to 'server/models/application.js')
-rw-r--r--server/models/application.js45
1 files changed, 25 insertions, 20 deletions
diff --git a/server/models/application.js b/server/models/application.js
index 452ac4283..ec1d7b122 100644
--- a/server/models/application.js
+++ b/server/models/application.js
@@ -1,31 +1,36 @@
1const mongoose = require('mongoose') 1module.exports = function (sequelize, DataTypes) {
2 const Application = sequelize.define('Application',
3 {
4 sqlSchemaVersion: {
5 type: DataTypes.INTEGER,
6 defaultValue: 0
7 }
8 },
9 {
10 classMethods: {
11 loadSqlSchemaVersion,
12 updateSqlSchemaVersion
13 }
14 }
15 )
16
17 return Application
18}
2 19
3// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
4 21
5const ApplicationSchema = mongoose.Schema({ 22function loadSqlSchemaVersion (callback) {
6 mongoSchemaVersion: { 23 const query = {
7 type: Number, 24 attributes: [ 'sqlSchemaVersion' ]
8 default: 0
9 } 25 }
10})
11
12ApplicationSchema.statics = {
13 loadMongoSchemaVersion,
14 updateMongoSchemaVersion
15}
16
17mongoose.model('Application', ApplicationSchema)
18
19// ---------------------------------------------------------------------------
20 26
21function loadMongoSchemaVersion (callback) { 27 return this.findOne(query).asCallback(function (err, data) {
22 return this.findOne({}, { mongoSchemaVersion: 1 }, function (err, data) { 28 const version = data ? data.sqlSchemaVersion : 0
23 const version = data ? data.mongoSchemaVersion : 0
24 29
25 return callback(err, version) 30 return callback(err, version)
26 }) 31 })
27} 32}
28 33
29function updateMongoSchemaVersion (newVersion, callback) { 34function updateSqlSchemaVersion (newVersion, callback) {
30 return this.update({}, { mongoSchemaVersion: newVersion }, callback) 35 return this.update({ sqlSchemaVersion: newVersion }).asCallback(callback)
31} 36}