import { MigrationInterface, QueryRunner } from "typeorm"

export class AddTeamLeadIdToEmployees1761647374805 implements MigrationInterface {
  name = "AddTeamLeadIdToEmployees1761647374805"

  public async up(queryRunner: QueryRunner): Promise<void> {
    // Add team_lead_id column to employees table
    await queryRunner.query(
      `ALTER TABLE "employees" ADD "team_lead_id" integer`,
    )

    // Add foreign key constraint for team_lead_id referencing employees.id
    await queryRunner.query(
      `ALTER TABLE "employees" ADD CONSTRAINT "FK_employees_team_lead_id" FOREIGN KEY ("team_lead_id") REFERENCES "employees"("id") ON DELETE SET NULL ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    // Drop foreign key constraint
    await queryRunner.query(
      `ALTER TABLE "employees" DROP CONSTRAINT "FK_employees_team_lead_id"`,
    )

    // Drop team_lead_id column
    await queryRunner.query(
      `ALTER TABLE "employees" DROP COLUMN "team_lead_id"`,
    )
  }
}
