Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

487
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda