]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/application/application.ts
Move models to typescript-sequelize
[github/Chocobozzz/PeerTube.git] / server / models / application / application.ts
1 import { Transaction } from 'sequelize'
2 import { AllowNull, Column, Default, IsInt, Model, Table } from 'sequelize-typescript'
3
4 @Table({
5 tableName: 'application'
6 })
7 export class ApplicationModel extends Model<ApplicationModel> {
8
9 @AllowNull(false)
10 @Default(0)
11 @IsInt
12 @Column
13 migrationVersion: number
14
15 static countTotal () {
16 return ApplicationModel.count()
17 }
18
19 static loadMigrationVersion () {
20 const query = {
21 attributes: [ 'migrationVersion' ]
22 }
23
24 return ApplicationModel.findOne(query).then(data => data ? data.migrationVersion : null)
25 }
26
27 static updateMigrationVersion (newVersion: number, transaction: Transaction) {
28 const options = {
29 where: {},
30 transaction: transaction
31 }
32
33 return ApplicationModel.update({ migrationVersion: newVersion }, options)
34 }
35 }