]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/application.js
Server: add updatedAt attribute to videos
[github/Chocobozzz/PeerTube.git] / server / models / application.js
CommitLineData
67bf9b96
C
1'use strict'
2
feb4bdfd
C
3module.exports = function (sequelize, DataTypes) {
4 const Application = sequelize.define('Application',
5 {
b769007f 6 migrationVersion: {
feb4bdfd 7 type: DataTypes.INTEGER,
67bf9b96
C
8 defaultValue: 0,
9 allowNull: false,
10 validate: {
11 isInt: true
12 }
feb4bdfd
C
13 }
14 },
15 {
16 classMethods: {
b769007f
C
17 loadMigrationVersion,
18 updateMigrationVersion
feb4bdfd
C
19 }
20 }
21 )
22
23 return Application
24}
00d6b0dd
C
25
26// ---------------------------------------------------------------------------
27
b769007f 28function loadMigrationVersion (callback) {
feb4bdfd 29 const query = {
b769007f 30 attributes: [ 'migrationVersion' ]
00d6b0dd 31 }
00d6b0dd 32
feb4bdfd 33 return this.findOne(query).asCallback(function (err, data) {
b769007f 34 const version = data ? data.migrationVersion : 0
00d6b0dd
C
35
36 return callback(err, version)
37 })
38}
39
b769007f
C
40function updateMigrationVersion (newVersion, transaction, 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)
00d6b0dd 52}