Vue-cli-plugin-electron-builder: Cannot get Umzug to work. It fires no such file or directory when trying to load the migrations folder after bundling.

Created on 14 Apr 2020  路  4Comments  路  Source: nklayman/vue-cli-plugin-electron-builder

Describe the bug
The Umzug framework is unable to load the migrations folder after bundling. It fires no such file or directory migrations.

To Reproduce
Steps to reproduce the behavior:

  1. Install Umzug.
  2. Write this piece of code, to run Umzug every time you launch the program.
const umzug = new Umzug({
  migrations: {
    path: path.join(__dirname, './migrations'),
    params: [
      sequelize.getQueryInterface()
    ]
  },
  storage: 'sequelize',
  storageOptions: {
    sequelize: sequelize
  }
})
;(async () => {
  try {
    await umzug.up()
  } catch(e) {
    console.log('Umzug Error', e)
  }
  console.log('All migrations performed successfully')
})()

Expected behavior
I expect the migrations in the migrations folder to get migrated.

Screenshots
But instead I get this error:
Operational Error: ENOENT no such file or directory, scandir H:/learnvue/ve/dist_electron/migrations
https://prnt.sc/ryp5zd
And here is my project folders:
prntscr.com/ryp3tx

Additional context
When I was importing the models from the models folder I did it this way (instead of the readdirSync method) and it works:

const context = require.context('.', true, /^\.\/(?!index\.js).*\.js$/, 'sync')
context.keys().map(context).forEach(module => {
  const sequelizeModel = module(sequelize, Sequelize);
  db[sequelizeModel.name] = sequelizeModel;
})

All 4 comments

I am doing a similar thing with typeorm. What worked for me was using the extraResources option in vue.config.js and copying all entities and migrations into there, then telling typeorm to refer to that location in a production environment.

Try marking umzug as an external by setting your vue.config.js to:

module.exports = {
  pluginOptions: {
    electronBuilder: {
      externals: ['umzug']
    }
  }
}

You can also store the migrations in the public folder. The path to this folder is available in __static.

I tried both @nklayman solutions and they both worked just fine.
I also found another solution that has to do with the Umzug itself which is a new feature they added that helps you specify a list of migrations without using a file loader. https://github.com/sequelize/umzug/pull/199

Thank you very much for the help.

Was this page helpful?
0 / 5 - 0 ratings