import { MigrationInterface, QueryRunner } from 'typeorm';

export class AttendanceCheckoutNote1780990000000 implements MigrationInterface {
  name = 'AttendanceCheckoutNote1780990000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    const table = await queryRunner.getTable('attendances');
    const hasCheckoutNote = table?.columns.some(
      (column) => column.name === 'checkout_note',
    );

    if (!hasCheckoutNote) {
      await queryRunner.query(
        `ALTER TABLE \`attendances\` ADD \`checkout_note\` varchar(191) NULL AFTER \`note\``,
      );
    }
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    const table = await queryRunner.getTable('attendances');
    const hasCheckoutNote = table?.columns.some(
      (column) => column.name === 'checkout_note',
    );

    if (hasCheckoutNote) {
      await queryRunner.query(
        `ALTER TABLE \`attendances\` DROP COLUMN \`checkout_note\``,
      );
    }
  }
}
