]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/application.js
Update migrations code
[github/Chocobozzz/PeerTube.git] / server / models / application.js
CommitLineData
feb4bdfd
C
1module.exports = function (sequelize, DataTypes) {
2 const Application = sequelize.define('Application',
3 {
b769007f 4 migrationVersion: {
feb4bdfd
C
5 type: DataTypes.INTEGER,
6 defaultValue: 0
7 }
8 },
9 {
10 classMethods: {
b769007f
C
11 loadMigrationVersion,
12 updateMigrationVersion
feb4bdfd
C
13 }
14 }
15 )
16
17 return Application
18}
00d6b0dd
C
19
20// ---------------------------------------------------------------------------
21
b769007f 22function loadMigrationVersion (callback) {
feb4bdfd 23 const query = {
b769007f 24 attributes: [ 'migrationVersion' ]
00d6b0dd 25 }
00d6b0dd 26
feb4bdfd 27 return this.findOne(query).asCallback(function (err, data) {
b769007f 28 const version = data ? data.migrationVersion : 0
00d6b0dd
C
29
30 return callback(err, version)
31 })
32}
33
b769007f
C
34function 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)
00d6b0dd 46}