diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/models/application.ts | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/models/application.ts')
-rw-r--r-- | server/models/application.ts | 50 |
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 @@ | |||
1 | module.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 | |||
26 | function 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 | |||
38 | function 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 | } | ||