aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/models/application.js
blob: ec1d7b1227c70bf1ce8f3254a2e59e16afc699d6 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                     


                                                                              


                                          
   
 

                                                              




                                 

                                                                           
 
module.exports = function (sequelize, DataTypes) {
  const Application = sequelize.define('Application',
    {
      sqlSchemaVersion: {
        type: DataTypes.INTEGER,
        defaultValue: 0
      }
    },
    {
      classMethods: {
        loadSqlSchemaVersion,
        updateSqlSchemaVersion
      }
    }
  )

  return Application
}

// ---------------------------------------------------------------------------

function loadSqlSchemaVersion (callback) {
  const query = {
    attributes: [ 'sqlSchemaVersion' ]
  }

  return this.findOne(query).asCallback(function (err, data) {
    const version = data ? data.sqlSchemaVersion : 0

    return callback(err, version)
  })
}

function updateSqlSchemaVersion (newVersion, callback) {
  return this.update({ sqlSchemaVersion: newVersion }).asCallback(callback)
}