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