Skip to content

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

@Yash17Agrawal

Description

@Yash17Agrawal

"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"
                    )
                ]
            ]
        }
    });
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions