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