aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/application/application.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/application/application.ts')
-rw-r--r--server/models/application/application.ts80
1 files changed, 27 insertions, 53 deletions
diff --git a/server/models/application/application.ts b/server/models/application/application.ts
index 8ba40a895..f3c0f1052 100644
--- a/server/models/application/application.ts
+++ b/server/models/application/application.ts
@@ -1,61 +1,35 @@
1import * as Sequelize from 'sequelize' 1import { Transaction } from 'sequelize'
2 2import { AllowNull, Column, Default, IsInt, Model, Table } from 'sequelize-typescript'
3import { addMethodsToModel } from '../utils' 3
4import { 4@Table({
5 ApplicationAttributes, 5 tableName: 'application'
6 ApplicationInstance, 6})
7 7export class ApplicationModel extends Model<ApplicationModel> {
8 ApplicationMethods 8
9} from './application-interface' 9 @AllowNull(false)
10 10 @Default(0)
11let Application: Sequelize.Model<ApplicationInstance, ApplicationAttributes> 11 @IsInt
12let loadMigrationVersion: ApplicationMethods.LoadMigrationVersion 12 @Column
13let updateMigrationVersion: ApplicationMethods.UpdateMigrationVersion 13 migrationVersion: number
14let countTotal: ApplicationMethods.CountTotal 14
15 static countTotal () {
16 return ApplicationModel.count()
17 }
15 18
16export default function defineApplication (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 19 static loadMigrationVersion () {
17 Application = sequelize.define<ApplicationInstance, ApplicationAttributes>('Application', 20 const query = {
18 { 21 attributes: [ 'migrationVersion' ]
19 migrationVersion: {
20 type: DataTypes.INTEGER,
21 defaultValue: 0,
22 allowNull: false,
23 validate: {
24 isInt: true
25 }
26 }
27 } 22 }
28 )
29
30 const classMethods = [
31 countTotal,
32 loadMigrationVersion,
33 updateMigrationVersion
34 ]
35 addMethodsToModel(Application, classMethods)
36
37 return Application
38}
39 23
40// --------------------------------------------------------------------------- 24 return ApplicationModel.findOne(query).then(data => data ? data.migrationVersion : null)
41
42countTotal = function () {
43 return this.count()
44}
45
46loadMigrationVersion = function () {
47 const query = {
48 attributes: [ 'migrationVersion' ]
49 } 25 }
50 26
51 return Application.findOne(query).then(data => data ? data.migrationVersion : null) 27 static updateMigrationVersion (newVersion: number, transaction: Transaction) {
52} 28 const options = {
29 where: {},
30 transaction: transaction
31 }
53 32
54updateMigrationVersion = function (newVersion: number, transaction: Sequelize.Transaction) { 33 return ApplicationModel.update({ migrationVersion: newVersion }, options)
55 const options: Sequelize.UpdateOptions = {
56 where: {},
57 transaction: transaction
58 } 34 }
59
60 return Application.update({ migrationVersion: newVersion }, options)
61} 35}