aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/application.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/application.ts')
-rw-r--r--server/models/application.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/server/models/application.ts b/server/models/application.ts
new file mode 100644
index 000000000..38a57e327
--- /dev/null
+++ b/server/models/application.ts
@@ -0,0 +1,50 @@
1module.exports = function (sequelize, DataTypes) {
2 const Application = sequelize.define('Application',
3 {
4 migrationVersion: {
5 type: DataTypes.INTEGER,
6 defaultValue: 0,
7 allowNull: false,
8 validate: {
9 isInt: true
10 }
11 }
12 },
13 {
14 classMethods: {
15 loadMigrationVersion,
16 updateMigrationVersion
17 }
18 }
19 )
20
21 return Application
22}
23
24// ---------------------------------------------------------------------------
25
26function loadMigrationVersion (callback) {
27 const query = {
28 attributes: [ 'migrationVersion' ]
29 }
30
31 return this.findOne(query).asCallback(function (err, data) {
32 const version = data ? data.migrationVersion : null
33
34 return callback(err, version)
35 })
36}
37
38function updateMigrationVersion (newVersion, transaction, callback) {
39 const options: { where?: any, transaction?: any } = {
40 where: {}
41 }
42
43 if (!callback) {
44 transaction = callback
45 } else {
46 options.transaction = transaction
47 }
48
49 return this.update({ migrationVersion: newVersion }, options).asCallback(callback)
50}