1
0
Fork 0
peertube/server/models/application.js

47 lines
981 B
JavaScript
Raw Normal View History

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,
defaultValue: 0
}
},
{
classMethods: {
2016-12-25 03:44:57 -05:00
loadMigrationVersion,
updateMigrationVersion
2016-12-11 15:50:51 -05:00
}
}
)
return Application
}
// ---------------------------------------------------------------------------
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-12-11 15:50:51 -05:00
return this.findOne(query).asCallback(function (err, data) {
2016-12-25 03:44:57 -05:00
const version = data ? data.migrationVersion : 0
return callback(err, version)
})
}
2016-12-25 03:44:57 -05: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)
}