如何在 umzug 配置中传递一组迁移实例

How to pass an array of migration instances in umzug config

我正在使用 umzug 运行 我的 electron-vue 应用程序中的迁移,因为 webpack 我不能使用

这样的路径
migrations: {
    path: __dirname + '/../migrations',
    pattern: /\.js$/
}

所以我听说我可以传递迁移实例,但我不知道我是怎么做到的。

到目前为止我有这个:

// sequelize initialization, etc...

let migrations = [
    require('../migrations/20180427160552-create-user'),
    require('../migrations/20180515205633-create-visits'),
    require('../migrations/20180515205633-create-vehicles')
];

var Umzug = require('umzug');
var umzug = new Umzug({
    storage: 'sequelize',
    storageOptions: {
    sequelize: sequelize
    },
    migrations: migrations
});
umzug.up().then(function (migrations) { });

您可以使用 customResolver

async function checkMigrations() {
  const umzug = new Umzug({
    storage: 'sequelize',
    storageOptions: {
      sequelize,
    },
    migrations: {
      params: [
        sequelize.getQueryInterface(),
        Sequelize,
        function() {
          throw new Error('Migration tried to use old style "done" callback.');
        }
      ],
      path: 'path/to/migrations',
      pattern: /\.js$/,
      customResolver: function(migrationFile) {
        return require(`./migrations/${path.basename(migrationFile, '.js')}`);
      }
    },
    logging: function() {
      console.log.apply(null, arguments);
    },
  });

  return umzug.up();
}

重点是将 "prefix" 文件夹用作文字,而不是变量。 这行不通:

customResolver: function(migrationFile) {
    return require(`${some-path}/${some-file}`);
}

但这将:

customResolver: function(migrationFile) {
    return require(`/absolute-or-relative-prefix-folder/${filename-based-on-func-argument}`);
}