How to programmatically start the sequence of migrations

The sequelize documentation seems outdated since they no longer support running migrations from sequelize itself, but instead rely on sequelize-cli. Is there an example of how to programmatically use sequeliz-cli to run recent migrations? All documentation seems to focus on using the client in a shell.

There seems to be a db: migrate function in db.js that I can possibly include.

https://github.com/sequelize/cli/blob/master/lib/tasks/db.js

+5
source share
1 answer

I am in the code for the command , and there it is enough that, IMHO, the simplest / best approach is to simply run the command in a child process. Here is the code I used for this (as an expected promise): sequelize db:migrate sequelize db:migrate

const {exec} = require('child_process');

await new Promise((resolve, reject) => {
  const migrate = exec(
    'sequelize db:migrate',
    {env: process.env},
    (err, stdout, stderr) => {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    }
  );

  // Forward stdout+stderr to this process
  migrate.stdout.pipe(process.stdout);
  migrate.stderr.pipe(process.stderr);
});
+2
source

All Articles