2016-12-28 08:49:23 -06:00
|
|
|
'use strict'
|
|
|
|
|
2016-12-11 14:50:51 -06:00
|
|
|
module.exports = function (sequelize, DataTypes) {
|
|
|
|
const Application = sequelize.define('Application',
|
|
|
|
{
|
2016-12-25 02:44:57 -06:00
|
|
|
migrationVersion: {
|
2016-12-11 14:50:51 -06:00
|
|
|
type: DataTypes.INTEGER,
|
2016-12-28 08:49:23 -06:00
|
|
|
defaultValue: 0,
|
|
|
|
allowNull: false,
|
|
|
|
validate: {
|
|
|
|
isInt: true
|
|
|
|
}
|
2016-12-11 14:50:51 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
classMethods: {
|
2016-12-25 02:44:57 -06:00
|
|
|
loadMigrationVersion,
|
|
|
|
updateMigrationVersion
|
2016-12-11 14:50:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return Application
|
|
|
|
}
|
2016-09-26 15:36:36 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2016-12-25 02:44:57 -06:00
|
|
|
function loadMigrationVersion (callback) {
|
2016-12-11 14:50:51 -06:00
|
|
|
const query = {
|
2016-12-25 02:44:57 -06:00
|
|
|
attributes: [ 'migrationVersion' ]
|
2016-09-26 15:36:36 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 14:50:51 -06:00
|
|
|
return this.findOne(query).asCallback(function (err, data) {
|
2017-03-04 03:40:09 -06:00
|
|
|
const version = data ? data.migrationVersion : null
|
2016-09-26 15:36:36 -05:00
|
|
|
|
|
|
|
return callback(err, version)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-25 02:44:57 -06:00
|
|
|
function updateMigrationVersion (newVersion, transaction, callback) {
|
|
|
|
const options = {
|
|
|
|
where: {}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!callback) {
|
|
|
|
transaction = callback
|
|
|
|
} else {
|
|
|
|
options.transaction = transaction
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.update({ migrationVersion: newVersion }, options).asCallback(callback)
|
2016-09-26 15:36:36 -05:00
|
|
|
}
|