aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/application.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-12 15:20:03 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-12 15:20:03 +0100
commit99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch)
treec9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/models/application.js
parentfcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff)
parent91cc839af88730ba55f84997c56b85ea100070a7 (diff)
downloadPeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz
PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst
PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip
Merge branch 'postgresql'
Diffstat (limited to 'server/models/application.js')
-rw-r--r--server/models/application.js61
1 files changed, 41 insertions, 20 deletions
diff --git a/server/models/application.js b/server/models/application.js
index 452ac4283..46dcfde33 100644
--- a/server/models/application.js
+++ b/server/models/application.js
@@ -1,31 +1,52 @@
1const mongoose = require('mongoose') 1'use strict'
2
3module.exports = function (sequelize, DataTypes) {
4 const Application = sequelize.define('Application',
5 {
6 migrationVersion: {
7 type: DataTypes.INTEGER,
8 defaultValue: 0,
9 allowNull: false,
10 validate: {
11 isInt: true
12 }
13 }
14 },
15 {
16 classMethods: {
17 loadMigrationVersion,
18 updateMigrationVersion
19 }
20 }
21 )
22
23 return Application
24}
2 25
3// --------------------------------------------------------------------------- 26// ---------------------------------------------------------------------------
4 27
5const ApplicationSchema = mongoose.Schema({ 28function loadMigrationVersion (callback) {
6 mongoSchemaVersion: { 29 const query = {
7 type: Number, 30 attributes: [ 'migrationVersion' ]
8 default: 0
9 } 31 }
10})
11
12ApplicationSchema.statics = {
13 loadMongoSchemaVersion,
14 updateMongoSchemaVersion
15}
16
17mongoose.model('Application', ApplicationSchema)
18
19// ---------------------------------------------------------------------------
20 32
21function loadMongoSchemaVersion (callback) { 33 return this.findOne(query).asCallback(function (err, data) {
22 return this.findOne({}, { mongoSchemaVersion: 1 }, function (err, data) { 34 const version = data ? data.migrationVersion : 0
23 const version = data ? data.mongoSchemaVersion : 0
24 35
25 return callback(err, version) 36 return callback(err, version)
26 }) 37 })
27} 38}
28 39
29function updateMongoSchemaVersion (newVersion, callback) { 40function updateMigrationVersion (newVersion, transaction, callback) {
30 return this.update({}, { mongoSchemaVersion: newVersion }, callback) 41 const options = {
42 where: {}
43 }
44
45 if (!callback) {
46 transaction = callback
47 } else {
48 options.transaction = transaction
49 }
50
51 return this.update({ migrationVersion: newVersion }, options).asCallback(callback)
31} 52}