import { MigrationInterface, QueryRunner } from "typeorm";

export class FixAttendanceValidationCollations1788120000000 implements MigrationInterface {
  name = "FixAttendanceValidationCollations1788120000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`SET FOREIGN_KEY_CHECKS = 0;`);

    const tables = [
      "attendance_settings",
      "attendances",
      "teacher_devices",
      "device_change_requests",
      "qr_attendance_points",
      "ip_whitelists",
      "work_day_schedules",
      "members",
      "owner",
      "working_schedule",
      "leave_policy",
      "departments",
      "designations",
      "locations",
      "employement_types",
      "hiring_sources",
      "attendance_requests",
      "leaves",
      "holidays",
      "events",
      "notices",
      "notifications",
    ];

    for (const table of tables) {
      try {
        await queryRunner.query(
          `ALTER TABLE \`${table}\` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci`,
        );
      } catch (e) {}
    }

    await queryRunner.query(`SET FOREIGN_KEY_CHECKS = 1;`);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {}
}
