refactor: umzug

allow umzug v3 to work with the umzug v2 migrations

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares
2026-08-21 20:23:17 +02:00
committed by Philip Molares
parent dcdf30b4c4
commit 788676aba4

View File

@@ -4,7 +4,7 @@ const fs = require('fs')
const path = require('path') const path = require('path')
const Sequelize = require('sequelize') const Sequelize = require('sequelize')
const { cloneDeep } = require('lodash') const { cloneDeep } = require('lodash')
const Umzug = require('umzug') const { SequelizeStorage, Umzug } = require('umzug')
// core // core
const config = require('../config') const config = require('../config')
@@ -66,21 +66,24 @@ Object.keys(db).forEach(function (modelName) {
const umzug = new Umzug({ const umzug = new Umzug({
migrations: { migrations: {
path: path.resolve(__dirname, '..', 'migrations'), glob: path.resolve(__dirname, '..', 'migrations', '*.js'),
params: [ resolve: ({ name, path, context }) => {
sequelize.getQueryInterface(), // Adjust the migration from the new signature to the v2 signature, making easier to upgrade to v3
Sequelize.DataTypes const migration = require(path)
] return {
name,
up: async () => migration.up(context, Sequelize),
down: async () => migration.down(context, Sequelize)
}
}
}, },
context: sequelize.getQueryInterface(),
// Required wrapper function required to prevent winstion issue // Required wrapper function required to prevent winstion issue
// https://github.com/winstonjs/winston/issues/1577 // https://github.com/winstonjs/winston/issues/1577
logging: message => { logging: message => {
logger.info(message) logger.info(message)
}, },
storage: 'sequelize', storage: new SequelizeStorage({ sequelize })
storageOptions: {
sequelize
}
}) })
db.runMigrations = async function runMigrations () { db.runMigrations = async function runMigrations () {