blob: 4114ed76de12b10981994646aee0cdaa4ca6700c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
module.exports = function (sequelize, DataTypes) {
const Application = sequelize.define('Application',
{
migrationVersion: {
type: DataTypes.INTEGER,
defaultValue: 0
}
},
{
classMethods: {
loadMigrationVersion,
updateMigrationVersion
}
}
)
return Application
}
// ---------------------------------------------------------------------------
function loadMigrationVersion (callback) {
const query = {
attributes: [ 'migrationVersion' ]
}
return this.findOne(query).asCallback(function (err, data) {
const version = data ? data.migrationVersion : 0
return callback(err, version)
})
}
function updateMigrationVersion (newVersion, transaction, callback) {
const options = {
where: {}
}
if (!callback) {
transaction = callback
} else {
options.transaction = transaction
}
return this.update({ migrationVersion: newVersion }, options).asCallback(callback)
}
|