Refractor videos AP functions
[oweals/peertube.git] / server / models / application / application.ts
1 import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
2 import { AccountModel } from '../account/account'
3
4 @DefaultScope({
5   include: [
6     {
7       model: () => AccountModel,
8       required: true
9     }
10   ]
11 })
12 @Table({
13   tableName: 'application'
14 })
15 export class ApplicationModel extends Model<ApplicationModel> {
16
17   @AllowNull(false)
18   @Default(0)
19   @IsInt
20   @Column
21   migrationVersion: number
22
23   @HasOne(() => AccountModel, {
24     foreignKey: {
25       allowNull: true
26     },
27     onDelete: 'cascade'
28   })
29   Account: AccountModel
30
31   static countTotal () {
32     return ApplicationModel.count()
33   }
34
35   static load () {
36     return ApplicationModel.findOne()
37   }
38 }