aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/application/application.ts
blob: f3c0f1052735c2749110a0c7bf2296086763fa84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Transaction } from 'sequelize'
import { AllowNull, Column, Default, IsInt, Model, Table } from 'sequelize-typescript'

@Table({
  tableName: 'application'
})
export class ApplicationModel extends Model<ApplicationModel> {

  @AllowNull(false)
  @Default(0)
  @IsInt
  @Column
  migrationVersion: number

  static countTotal () {
    return ApplicationModel.count()
  }

  static loadMigrationVersion () {
    const query = {
      attributes: [ 'migrationVersion' ]
    }

    return ApplicationModel.findOne(query).then(data => data ? data.migrationVersion : null)
  }

  static updateMigrationVersion (newVersion: number, transaction: Transaction) {
    const options = {
      where: {},
      transaction: transaction
    }

    return ApplicationModel.update({ migrationVersion: newVersion }, options)
  }
}