import { MigrationInterface, QueryRunner } from "typeorm";

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

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

    const tables = [
      "onboarding_templates",
      "onboarding_template_tasks",
      "onboarding_cases",
      "onboarding_tasks",
      "onboarding_documents",
      "provisioning_items",
      "buddy_assignments",
      "onboarding_surveys",
      "probations",
      "probation_reviews",
      "offboarding_templates",
      "offboarding_template_tasks",
      "offboarding_cases",
      "offboarding_tasks",
      "equipment_returns",
      "exit_interview_templates",
      "exit_interviews",
      "final_settlements",
      "final_settlement_items",
    ];

    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> {}
}
