Skip to content

ESM & sequelize db:migrate #1156

@mahnunchik

Description

@mahnunchik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions