ESM & sequelize db:migrate

Open
#1,156 31 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, node.js
Domain
cli, databases

Research direction

Start by running npx sequelize db:migrate with the migration shown in db/migrations/20220924162319-create-test.js, then inspect the module-loading path reported in umzug/lib/migration.js. Compare the CLI's handling of CommonJS and ESM migrations; done means the example migration runs successfully without the require() error.

Written by the indexing model from the issue text.

Description

It would be great if sequelize-cli supports migrations in ESM way.

What you are doing?

// db/migrations/20220924162319-create-test.js
export async function up(queryInterface, Sequelize) {
  await queryInterface.createTable('test', {
    id: {
      type: Sequelize.DataTypes.INTEGER,
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
    },
    createdAt: {
      allowNull: false,
      type: Sequelize.DataTypes.DATE,
    },
    updatedAt: {
      allowNull: false,
      type: Sequelize.DataTypes.DATE,
    }
  });
}
export function down(queryInterface, Sequelize) {
  return queryInterface.dropTable('test');
}
npx sequelize db:migrate

What do you expect to happen?

Migration works.

What is actually happening?

npx sequelize db:migrate

Sequelize CLI [Node: 16.16.0, CLI: 6.4.1, ORM: 6.23.0]

Loaded configuration file "db/config.js".
== 20220924162319-create-test: migrating =======

ERROR: require() of ES Module /test/db/migrations/20220924162319-create-test.js from /test/node_modules/umzug/lib/migration.js not supported.
Instead change the require of 20220924162319-create-test.js in /test/node_modules/umzug/lib/migration.js to a dynamic import() which is available in all CommonJS modules.

Output, either JSON or SQL

Dialect: postgres
Database version: 12
Sequelize CLI version: 6.4.1
Sequelize version: 6.23.0

Dominant language
JavaScript
Stars
2.6k
Forks
524
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sequelize/cli

All issues in sequelize/cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.