1

im using sequlize with umzug - migrations work locally, when i create a job for it, it cannot find the neccessery modules.

I got a mirgrator.js file.

const { migrator } = require('./iumzug.js');

migrator.runAsCLI()

And an iumzug.ts file as well, which configured like this.

const { Sequelize } = require('sequelize');
const { envVar } = require('./src/utilities/env-var')
const { Umzug, SequelizeStorage } = require("umzug")

const sequelize = new Sequelize({
  database: envVar.DB_DATABASE,
  host: envVar.DB_HOST,
  port: 5432,
  schema: ["TEST"].includes(envVar.NODE_ENV) ? 'test' : 'public',
  username: envVar.DB_USERNAME,
  password: envVar.DB_PASSWORD,
  dialect: 'postgres',
  ssl: true,
  dialectOptions: {
    ssl: {
      require: true,
    },},});

const migrator = new Umzug({
  migrations: {
    glob: ["./src/database/*.ts", { cwd: __dirname }],
    resolve: ({ name, path, context }) => {
      // eslint-disable-next-line @typescript-eslint/no-var-requires
      const migration = require(path);
      return {
        // adjust the parameters Umzug will
        // pass to migration methods when called
        name,
        up: async () => migration.up(context, Sequelize),
        down: async () => migration.down(context, Sequelize)
      };
    }
  },
  context: sequelize.getQueryInterface(),
  storage: new SequelizeStorage({
    sequelize,
    modelName: "migration_meta"
  }),
  logger: console
});

module.exports = { migrator }

i created a migration job on my github yml file as followes:

  migrations: 
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@v3
      - name: migrations step
        run: | 
            node migrator.js up

when i run github action - i get this error

enter image description here

looking for alternatives / directions to fix it. Let me know if i need to add anymore code / pictures of the process.

shahar
  • 89
  • 1
  • 5
  • 1
    Make sure to install the dependencies with `npm install`. You can use `-g` flag for global installations. I did something similar, I created a step for migrations but used `sequelize-cli` instead. – Niv Jan 16 '23 at 10:51

1 Answers1

0

you need to install all the required dependencies. Add the following steps before running the node app.

- name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: 18
- name: Install dependencies
        run: yarn
Paulo
  • 1
  • 1