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

Unnecessary migration generated for enum column when using MySQL/Aurora Data API after upgrade from v0.2.31 to v0.2.37 #8161

Closed
coyoteecd opened this issue Sep 7, 2021 · 0 comments · Fixed by #8164

Comments

@coyoteecd
Copy link
Contributor

coyoteecd commented Sep 7, 2021

Issue Description

I am rebasing my typeorm fork from v0.2.31 to latest master (~v0.2.37) and trying to use it in our project.
One of the issues I have is that after upgrade, generating migrations over an up-to-date existing database a rather high amount of unnecessary changes. One of the issues I could pinpoint is that all enum columns generate ALTER TABLE statements.

I believe the issue is in BaseQueryRunner here:

|| oldColumn.enum !== newColumn.enum;

The column enum property is documented to have all the enum values, and indeed when debugging both old and new column definitions have enum = array of enum (string) values. So we're comparing array references there. This code is broken for quite a while, I suspect the issue appeared due to some object cloning which made the array references be different.

Expected Behavior

No migrations generated

Actual Behavior

Unnecessary ALTER TABLE ... CHANGE column is generated.
Applying the migration does not solve the problem, generating a new migration afterwards keeps generating the same script.

Steps to Reproduce

Here's an example entity:

enum Status {
  First = 'First',
  Second = 'Second'
}

@Entity
export class User {
  @Column({ type: 'enum', enum: Status, default: Status.First })
  public status: Status;
}

Generating migrations produces the following:

export class test31631015251611 implements MigrationInterface {
  name = 'test31631015251611';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`ALTER TABLE \`user\` CHANGE \`status\` \`status\` enum ('First', 'Second') NOT NULL DEFAULT 'First'`);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`ALTER TABLE \`user\` CHANGE \`status\` \`status\` enum ('First', 'Second') NOT NULL DEFAULT 'First'`);
  }
}

My Environment

Dependency Version
Operating System
Node.js version v14.16.0
Typescript version 4.4.2
TypeORM version 0.2.37

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api yes
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql probably
nativescript no
oracle no
postgres no
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✅ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant