]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/application.js
Copy all keys in production example so if we chagne the default one
[github/Chocobozzz/PeerTube.git] / server / models / application.js
1 module.exports = function (sequelize, DataTypes) {
2 const Application = sequelize.define('Application',
3 {
4 migrationVersion: {
5 type: DataTypes.INTEGER,
6 defaultValue: 0
7 }
8 },
9 {
10 classMethods: {
11 loadMigrationVersion,
12 updateMigrationVersion
13 }
14 }
15 )
16
17 return Application
18 }
19
20 // ---------------------------------------------------------------------------
21
22 function loadMigrationVersion (callback) {
23 const query = {
24 attributes: [ 'migrationVersion' ]
25 }
26
27 return this.findOne(query).asCallback(function (err, data) {
28 const version = data ? data.migrationVersion : 0
29
30 return callback(err, version)
31 })
32 }
33
34 function updateMigrationVersion (newVersion, transaction, callback) {
35 const options = {
36 where: {}
37 }
38
39 if (!callback) {
40 transaction = callback
41 } else {
42 options.transaction = transaction
43 }
44
45 return this.update({ migrationVersion: newVersion }, options).asCallback(callback)
46 }