import { MigrationInterface, QueryRunner } from "typeorm"

export class AddMisReportRatingFeedbacksTable1773141357239 implements MigrationInterface {
  name = "AddMisReportRatingFeedbacksTable1773141357239"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "mis_report_rating_feedbacks" ("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, "company_id" integer NOT NULL, "employee_id" integer NOT NULL, "business_feedback" text, "technical_feedback" text, "personal_feedback" text, "business_rating" smallint NOT NULL DEFAULT '0', "technical_rating" smallint NOT NULL DEFAULT '0', "personal_rating" smallint NOT NULL DEFAULT '0', "average_rating" smallint NOT NULL DEFAULT '0', "action_by_id" integer NOT NULL, "month" smallint NOT NULL, "year" smallint NOT NULL, CONSTRAINT "PK_2992b02cde6c81cce1942a7246a" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "mis_report_rating_feedbacks" ADD CONSTRAINT "FK_39cc059ff0562d207f2cbc316c8" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "mis_report_rating_feedbacks" ADD CONSTRAINT "FK_3ea477c269940bbadc85d08de02" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "mis_report_rating_feedbacks" ADD CONSTRAINT "FK_84dc9da2138256ba864c6ccbb58" FOREIGN KEY ("action_by_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "mis_report_rating_feedbacks" DROP CONSTRAINT "FK_84dc9da2138256ba864c6ccbb58"`,
    )
    await queryRunner.query(
      `ALTER TABLE "mis_report_rating_feedbacks" DROP CONSTRAINT "FK_3ea477c269940bbadc85d08de02"`,
    )
    await queryRunner.query(
      `ALTER TABLE "mis_report_rating_feedbacks" DROP CONSTRAINT "FK_39cc059ff0562d207f2cbc316c8"`,
    )
    await queryRunner.query(`DROP TABLE "mis_report_rating_feedbacks"`)
  }
}
