Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

483
Views
TYPEORM Update updated date column based on a specific column's update

I have added two columns, 'Paid Amount' and 'Paid Date' to an existing table (MySQL) in TypeORM (nodeJS).

Here, I want 'Paid Date' to update only when 'Paid Amount' column is updated.

Is it possible to define 'Paid Date' in the migration or model?

Below is my source code.

migration.ts

export class addRefundCancellationFeesToReservationTables1644984542889 implements MigrationInterface {
    name = 'addRefundCancellationFeesToReservationTables1644984542889'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query("ALTER TABLE `reservation` ADD `paid_amount` int DEFAULT NULL");
        await queryRunner.query("ALTER TABLE `reservation` ADD `paid_date` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)");
        ....
....}

model.ts

.....
static readonly REFUND = 'paid_amount';
  @Column({ type: 'int', name: Reservation.PAID_AMOUNT, nullable: true })
  paidAmount: number | null;

  static readonly PAID_DATE = 'paid_date';
  @UpdateDateColumn({
    type: 'datetime',
    name: Reservation.PAID_DATE,
    precision: 3,
    default: () => 'CURRENT_TIMESTAMP(3)',
    onUpdate: 'CURRENT_TIMESTAMP(3)',
  })
  .....

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!