diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-12-11 21:50:51 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-12-19 21:22:28 +0100 |
commit | feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c (patch) | |
tree | 2abc9fbc9569760e218fd52835850b757344b420 /server/models/application.js | |
parent | 108626609eda75e4ecc0a83a650a4d53c46220e0 (diff) | |
download | PeerTube-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.js | 45 |
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 @@ | |||
1 | const mongoose = require('mongoose') | 1 | module.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 | ||
5 | const ApplicationSchema = mongoose.Schema({ | 22 | function loadSqlSchemaVersion (callback) { |
6 | mongoSchemaVersion: { | 23 | const query = { |
7 | type: Number, | 24 | attributes: [ 'sqlSchemaVersion' ] |
8 | default: 0 | ||
9 | } | 25 | } |
10 | }) | ||
11 | |||
12 | ApplicationSchema.statics = { | ||
13 | loadMongoSchemaVersion, | ||
14 | updateMongoSchemaVersion | ||
15 | } | ||
16 | |||
17 | mongoose.model('Application', ApplicationSchema) | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | 26 | ||
21 | function 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 | ||
29 | function updateMongoSchemaVersion (newVersion, callback) { | 34 | function updateSqlSchemaVersion (newVersion, callback) { |
30 | return this.update({}, { mongoSchemaVersion: newVersion }, callback) | 35 | return this.update({ sqlSchemaVersion: newVersion }).asCallback(callback) |
31 | } | 36 | } |