PeerTube/server/models/application/application.ts

36 lines
822 B
TypeScript
Raw Normal View History

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
}
2017-12-12 17:53:50 +01:00
return ApplicationModel.findOne(query).then(data => data ? data.migrationVersion : null)
}
2017-12-12 17:53:50 +01:00
static updateMigrationVersion (newVersion: number, transaction: Transaction) {
const options = {
where: {},
transaction: transaction
}
2017-12-12 17:53:50 +01:00
return ApplicationModel.update({ migrationVersion: newVersion }, options)
2016-12-25 09:44:57 +01:00
}
}