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)',
})
.....