import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Dedup stamp for the km/date-due maintenance alert — without it the daily
 * cron would re-notify every day a schedule stays due.
 */
export class AddMaintenanceDueNotifiedAt2480000000000 implements MigrationInterface {
  name = 'AddMaintenanceDueNotifiedAt2480000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.maintenance_schedules
        ADD COLUMN IF NOT EXISTS due_notified_at timestamptz NULL
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.maintenance_schedules DROP COLUMN IF EXISTS due_notified_at
    `);
  }
}
