mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Update migrations code
This commit is contained in:
parent
dd6019932e
commit
b769007f73
19 changed files with 161 additions and 348 deletions
|
@ -1,15 +1,15 @@
|
|||
module.exports = function (sequelize, DataTypes) {
|
||||
const Application = sequelize.define('Application',
|
||||
{
|
||||
sqlSchemaVersion: {
|
||||
migrationVersion: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
classMethods: {
|
||||
loadSqlSchemaVersion,
|
||||
updateSqlSchemaVersion
|
||||
loadMigrationVersion,
|
||||
updateMigrationVersion
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -19,18 +19,28 @@ module.exports = function (sequelize, DataTypes) {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function loadSqlSchemaVersion (callback) {
|
||||
function loadMigrationVersion (callback) {
|
||||
const query = {
|
||||
attributes: [ 'sqlSchemaVersion' ]
|
||||
attributes: [ 'migrationVersion' ]
|
||||
}
|
||||
|
||||
return this.findOne(query).asCallback(function (err, data) {
|
||||
const version = data ? data.sqlSchemaVersion : 0
|
||||
const version = data ? data.migrationVersion : 0
|
||||
|
||||
return callback(err, version)
|
||||
})
|
||||
}
|
||||
|
||||
function updateSqlSchemaVersion (newVersion, callback) {
|
||||
return this.update({ sqlSchemaVersion: newVersion }).asCallback(callback)
|
||||
function updateMigrationVersion (newVersion, transaction, callback) {
|
||||
const options = {
|
||||
where: {}
|
||||
}
|
||||
|
||||
if (!callback) {
|
||||
transaction = callback
|
||||
} else {
|
||||
options.transaction = transaction
|
||||
}
|
||||
|
||||
return this.update({ migrationVersion: newVersion }, options).asCallback(callback)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue