import { MigrationInterface, QueryRunner } from "typeorm"

export class AddBusinessKpisRatingsTable1773144010880 implements MigrationInterface {
  name = "AddBusinessKpisRatingsTable1773144010880"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "business_kpis_ratings" ("created_by" integer, "updated_by" integer, "deleted_by" integer, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, "id" SERIAL NOT NULL, "kpi_id" integer NOT NULL, "rating_id" integer NOT NULL, "employee_id" integer NOT NULL, "rating" smallint NOT NULL DEFAULT '0', "department_id" integer NOT NULL, "month" smallint NOT NULL, "year" smallint NOT NULL, CONSTRAINT "PK_6761b92ae041438c0b60a608752" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "business_kpis_ratings" ADD CONSTRAINT "FK_1597b511eec54ba035ef8920be5" FOREIGN KEY ("kpi_id") REFERENCES "mis_business_kpis"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "business_kpis_ratings" ADD CONSTRAINT "FK_ca822cf492c505107f2a7857db2" FOREIGN KEY ("rating_id") REFERENCES "mis_report_rating_feedbacks"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "business_kpis_ratings" ADD CONSTRAINT "FK_48dc3dc8bd119c144d0eb9ef461" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "business_kpis_ratings" ADD CONSTRAINT "FK_d8c3279244b41fe91374b421770" FOREIGN KEY ("department_id") REFERENCES "departments"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "business_kpis_ratings" DROP CONSTRAINT "FK_d8c3279244b41fe91374b421770"`,
    )
    await queryRunner.query(
      `ALTER TABLE "business_kpis_ratings" DROP CONSTRAINT "FK_48dc3dc8bd119c144d0eb9ef461"`,
    )
    await queryRunner.query(
      `ALTER TABLE "business_kpis_ratings" DROP CONSTRAINT "FK_ca822cf492c505107f2a7857db2"`,
    )
    await queryRunner.query(
      `ALTER TABLE "business_kpis_ratings" DROP CONSTRAINT "FK_1597b511eec54ba035ef8920be5"`,
    )
  }
}
