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

MigrationError: Migration 2024.06.20T07.13.41.random_file_name.ts (up) failed: Original error: migration.up is not a function #693

Open
Yash17Agrawal opened this issue Sep 30, 2024 · 0 comments

Comments

@Yash17Agrawal
Copy link

"mysql2": "^3.10.0",
"sequelize": "^6.37.3",
"umzug": "^3.8.1"
node version v20.10.0
We have migrations written in typescript like

import { MigrationParams } from "@local-types";
import { DataTypes } from "sequelize";

export const up = async ({ context: sequelize }: MigrationParams) => {
    await sequelize.addColumn(
       // some code
    );
};

export const down = async ({ context: sequelize }: MigrationParams) => {
    await sequelize.removeColumn(
        // some code
    );
};

which gets compiled to .js files and is run through nodejs lambda

The error is happening randomly without any concurrent pattern seen.
FYI: we have few files like random_file.ts.ts in between as tech debt but couldnt reproduce with them as well

also this is how i am initializing umzug

import fs from "fs";
import path from "path";
import { Sequelize } from "sequelize";
import { Umzug, SequelizeStorage } from "umzug";

interface Props {
    databaseName: string;
}

export const getUmzug = (
    sequelize: Sequelize,
    props?: Props,
    migrationsGlob?: string
) => {
    return new Umzug({
        migrations: {
            glob: "build/migrations/*.{ts,js}",
            resolve: ({ name, path, context }) => {
                const migration = require(path);
                return {
                    name: name.replace(/\.js$/, ".ts"),
                    up: async () =>
                        migration.up({
                            context,
                            ...(props && { databaseName: props.databaseName })
                        }),
                    down: async () => migration.down({ context })
                };
            }
        },
        context: sequelize.getQueryInterface(),
        storage: new SequelizeStorage({
            sequelize: sequelize,
            tableName: process.env.DB_META_TABLE_NAME || "SequelizeMeta"
        }),
        logger: console,
        create: {
            folder: "src/migrations",
            template: filePath => [
                [
                    filePath,
                    fs.readFileSync(
                        path.join(__dirname, "template", "sample-migration.ts"),
                        "utf-8"
                    )
                ]
            ]
        }
    });
};
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

1 participant