2017-12-12 17:53:50 +01:00
|
|
|
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()
|
|
|
|
}
|
2017-05-22 20:58:25 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
static loadMigrationVersion () {
|
|
|
|
const query = {
|
|
|
|
attributes: [ 'migrationVersion' ]
|
2016-12-11 21:50:51 +01:00
|
|
|
}
|
2016-09-26 22:36:36 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
return ApplicationModel.findOne(query).then(data => data ? data.migrationVersion : null)
|
2016-09-26 22:36:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
static updateMigrationVersion (newVersion: number, transaction: Transaction) {
|
|
|
|
const options = {
|
|
|
|
where: {},
|
|
|
|
transaction: transaction
|
|
|
|
}
|
2016-09-26 22:36:36 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
return ApplicationModel.update({ migrationVersion: newVersion }, options)
|
2016-12-25 09:44:57 +01:00
|
|
|
}
|
2016-09-26 22:36:36 +02:00
|
|
|
}
|