import { MigrationInterface, QueryRunner } from "typeorm"

export class CreateConsultantsTable1762412134989 implements MigrationInterface {
  name = "CreateConsultantsTable1762412134989"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "consultant_types" ("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, "type_name" character varying(255) NOT NULL, "company_id" integer NOT NULL, CONSTRAINT "PK_c5f93af1b43ee50458108feeaab" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `CREATE TABLE "consultants" ("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, "consultant_name" character varying(255) NOT NULL, "company_id" integer NOT NULL, "type_id" integer NOT NULL, "phone_number" character varying(255), "email" character varying(255), "project_id" integer, "notes" text, CONSTRAINT "PK_a2475ae93be71a51af11c55d678" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "consultant_types" ADD CONSTRAINT "FK_0b0483eba4e4c45a1eb378a7631" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "consultants" ADD CONSTRAINT "FK_6de65b2b48e8cb1cc9ec9b10321" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "consultants" ADD CONSTRAINT "FK_8d1cb12fad147f13c9916f95f8b" FOREIGN KEY ("type_id") REFERENCES "consultant_types"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "consultants" ADD CONSTRAINT "FK_2671a6b12c93e836825f460e147" FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "consultants" DROP CONSTRAINT "FK_2671a6b12c93e836825f460e147"`,
    )
    await queryRunner.query(
      `ALTER TABLE "consultants" DROP CONSTRAINT "FK_8d1cb12fad147f13c9916f95f8b"`,
    )
    await queryRunner.query(
      `ALTER TABLE "consultants" DROP CONSTRAINT "FK_6de65b2b48e8cb1cc9ec9b10321"`,
    )
    await queryRunner.query(
      `ALTER TABLE "consultant_types" DROP CONSTRAINT "FK_0b0483eba4e4c45a1eb378a7631"`,
    )
    await queryRunner.query(`DROP TABLE "consultants"`)
    await queryRunner.query(`DROP TABLE "consultant_types"`)
  }
}
