]>
Commit | Line | Data |
---|---|---|
1 | module.exports = function (sequelize, DataTypes) { | |
2 | const Application = sequelize.define('Application', | |
3 | { | |
4 | sqlSchemaVersion: { | |
5 | type: DataTypes.INTEGER, | |
6 | defaultValue: 0 | |
7 | } | |
8 | }, | |
9 | { | |
10 | classMethods: { | |
11 | loadSqlSchemaVersion, | |
12 | updateSqlSchemaVersion | |
13 | } | |
14 | } | |
15 | ) | |
16 | ||
17 | return Application | |
18 | } | |
19 | ||
20 | // --------------------------------------------------------------------------- | |
21 | ||
22 | function loadSqlSchemaVersion (callback) { | |
23 | const query = { | |
24 | attributes: [ 'sqlSchemaVersion' ] | |
25 | } | |
26 | ||
27 | return this.findOne(query).asCallback(function (err, data) { | |
28 | const version = data ? data.sqlSchemaVersion : 0 | |
29 | ||
30 | return callback(err, version) | |
31 | }) | |
32 | } | |
33 | ||
34 | function updateSqlSchemaVersion (newVersion, callback) { | |
35 | return this.update({ sqlSchemaVersion: newVersion }).asCallback(callback) | |
36 | } |