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

Generating migrations for UpdateDateColumn should generate on update clause #6995

Closed
2 of 21 tasks
jafio opened this issue Oct 31, 2020 · 0 comments · Fixed by #7057, mattwelke/typeorm-postgres-example#165 or newerton/gobarber-2-backend#17

Comments

@jafio
Copy link
Contributor

jafio commented Oct 31, 2020

Issue Description

Expected Behavior

I added a @UpdateDateColumn() and I generated a new Migration with this change. I think it should generate an ON UPDATE clause in the query to create this column. For example, a good result would be

await queryRunner.query("ALTER TABLE `operation` ADD `updatedDate` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)");

Actual Behavior

The generated migration for the @UpdateDateColumn() is the same as the @CreateDateColumn(). However, I don't think it's good.

For example, here is the generated code in the up() method to create the @CreateDateColumn() and the @UpdateDateColumn():

await queryRunner.query("ALTER TABLE `operation` ADD `createdDate` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)");
await queryRunner.query("ALTER TABLE `operation` ADD `updatedDate` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)");

Steps to Reproduce

  1. Add the folowing code to an existing entity:
@CreateDateColumn()
createdDate: Date;

@UpdateDateColumn()
updatedDate: Date;
  1. Generate the migration for this change
  2. If you look the up() method of the created migration, you should see the problem.

My Environment

Dependency Version
Operating System Linux Debian 10
Node.js version v13.14.0
Typescript version v3.7.4
TypeORM version v0.2.28

Relevant Database Driver(s)

  • aurora-data-api
  • aurora-data-api-pg
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

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, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment