Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Umzug 3.1.1 new SequelizeStorage() produces circular dependency error #556

Closed
brandon-kyle-bailey opened this issue May 26, 2022 Discussed in #555 · 2 comments
Closed

Comments

@brandon-kyle-bailey
Copy link

Discussed in #555

Originally posted by brandon-kyle-bailey May 26, 2022
Environment info:

  • "nodejs": "14.18.1"
  • "npm": "8.1.4"
  • "sequelize": "6.20.0"
  • "umzug": "3.1.1"
  • "pg": "8.7.3"
  • "typescript": "4.0.3"

Following the documentation to setup a migration flow with Sequelize and Umzug for a Postgres database presents the following error message:

{
    "errorType": "TypeError",
    "errorMessage": "Converting circular structure to JSON\n    --> starting at object with constructor 'Sequelize5'\n    |     property 'dialect' -> object with constructor 'PostgresDialect'\n    --- property 'sequelize' closes the circle",
    "stack": [
        "TypeError: Converting circular structure to JSON",
        "    --> starting at object with constructor 'Sequelize5'",
        "    |     property 'dialect' -> object with constructor 'PostgresDialect'",
        "    --- property 'sequelize' closes the circle",
        "    at JSON.stringify (<anonymous>)",
        "    at /var/task/index.js:87561:17",
        "    at /var/task/index.js:19377:31",
        "    at /var/task/index.js:23989:7",
        "    at Array.forEach (<anonymous>)",
        "    at sendLogEventToAppender (/var/task/index.js:23988:23)",
        "    at /var/task/index.js:19245:30",
        "    at Array.forEach (<anonymous>)",
        "    at sendToListeners (/var/task/index.js:19245:15)",
        "    at Object.send (/var/task/index.js:19296:9)"
    ]
}

Minimal code example:
runMigrations.ts

import { SequelizeStorage, Umzug } from "umzug";
import { Sequelize } from "sequelize";
import * as pg from "pg";

const sequelize = new Sequelize(dbname, username, password, {
    host,
    port,
    dialect: "postgres",
    dialectModule: pg,
});

const sequelizeStorage = new SequelizeStorage({ sequelize });

const umzug = new Umzug({
    ...
    storage: sequelizeStorage,
    context: { sequelize },
    logger: console,
});

Migration.ts

import DataTypes from "sequelize";

export const up = async ({ context: sequelize }: { context: any }) => {
    await sequelize.getQueryInterface().createTable("some-table-name", {
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: DataTypes.BIGINT,
        },
        activityFeedId: {
            type: DataTypes.UUID,
            allowNull: false,
        },
        activityId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: {
                    tableName: "some-other-table",
                },
                key: "id",
            },
        },
    });
};
export const down = async ({ context: sequelize }: { context: any }) => {
    await sequelize.getQueryInterface().dropTable("some-table-name");
};

The error presents when calling new SequelizeStorage() passing in the configures sequelize instance, per the documentation.

Kind of stuck on this. Any suggestions? TY!

@mmkal
Copy link
Contributor

mmkal commented May 27, 2022

Hmm something v similar was fixed by bumping emittery: 7baad24

could you check what emittery version is being resolved in your node_modules? Not sure how it’d end up with the wrong version but worth checking.

@mmkal
Copy link
Contributor

mmkal commented Aug 12, 2022

Going to close this as can't-reproduce / no-response. @brandon-kyle-bailey I suspect this is a dependencies issue, but since the latest umzug version requires the emittery version with the fix, I don't think there's anything more umzug can do. If it's a different issue, could you open a PR with a failing test case?

@mmkal mmkal closed this as completed Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants