Skip to content

Migration fails when altering existing columns #6949

@RoccoCocco

Description

@RoccoCocco

Describe the bug

With the recent upgrade from v6.0 to v6.5, migrations that use knex alter operation on existing columns is failing with message:

MigrationError: Migration my-migration (up) failed: Original error: Cannot read properties of undefined (reading 'get')

The migration in question

export class MyMigration extends Migration {
  async up(): Promise<void> {
    await this.ctx!.schema.alterTable(TABLE_NAME, function (table) {
      table.string('id', 255).alter();
    });
  }

  async down(): Promise<void> {
    await this.ctx!.schema.alterTable(TABLE_NAME, function (table) {
      table.string('id', 500).alter();
    });
  }
}

The workaround is to use raw alter queries via addSql, however we have used previous pattern extensively for our migrations so refactor is high effort for us right now.

The knex documentation is on older v2.5 version and from changelog, I'm unable to figure out what has changed or what the proper syntax is for alter in newer knex versions.

Reproduction

https://github.com/RoccoCocco/mikro-orm-migration-up-reproduction

What driver are you using?

@mikro-orm/postgresql

MikroORM version

6.5.9

Node.js version

18.20.8

Operating system

MacOS/Linux

Validations

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