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

Changing timestamptz length creates a bad down migration #5048

Closed
5 tasks done
stefansundin opened this issue Dec 26, 2023 · 0 comments
Closed
5 tasks done

Changing timestamptz length creates a bad down migration #5048

stefansundin opened this issue Dec 26, 2023 · 0 comments

Comments

@stefansundin
Copy link
Contributor

Describe the bug

Changing the length of a timestamptz property results in an incorrect down migration.

I encountered this when preparing for v6, since the migration for both up and down were essentially identical, so a rollback wouldn't work. I think it would be a good idea to fix this bug before releasing v6, since this will be a common migration people will perform.

Reproduction

export class User {
  @PrimaryKey({ columnType: 'uuid', defaultRaw: 'gen_random_uuid()' })
  id: string = uuid();

  @Property({
    defaultRaw: 'NOW()',
    length: 2, // change this to 3 and create the migration
  })
  createdAt: Date = new Date();
}

Create the migration:

yarn mikro-orm migration:create --name test

Results in:

export class Migration20231226222133_test extends Migration {
  async up(): Promise<void> {
    this.addSql('alter table "user" alter column "created_at" type timestamptz(3) using ("created_at"::timestamptz(3));');
  }

  async down(): Promise<void> {
    this.addSql('alter table "user" alter column "created_at" type timestamptz using ("created_at"::timestamptz);');
  }
}

The down migration should have timestamptz(2) instead of just timestamptz.

What driver are you using?

@mikro-orm/postgresql

MikroORM version

5.9.6

Node.js version

Node 18.18.2, TypeScript 5.3.3

Operating system

macOS 14.2.1

Validations

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