import { MigrationInterface, QueryRunner } from "typeorm"

export class CreateProjectActivitiesTable1775112148002 implements MigrationInterface {
  name = "CreateProjectActivitiesTable1775112148002"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "project_activities" ("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, "project_id" integer NOT NULL, "activity_type_id" integer NOT NULL, CONSTRAINT "PK_f322a4f9aed232d8868d54ec30c" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `CREATE UNIQUE INDEX "IDX_deb28c8e1a30e7b6445a873f11" ON "project_activities" ("project_id", "activity_type_id") `,
    )
    await queryRunner.query(
      `ALTER TABLE "project_activities" ADD CONSTRAINT "FK_da57aaa2cda866acedacc09867f" FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "project_activities" ADD CONSTRAINT "FK_312b6e8a98957362dfdac4f1bdf" FOREIGN KEY ("activity_type_id") REFERENCES "activity_types"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "project_activities" DROP CONSTRAINT "FK_312b6e8a98957362dfdac4f1bdf"`,
    )
    await queryRunner.query(
      `ALTER TABLE "project_activities" DROP CONSTRAINT "FK_da57aaa2cda866acedacc09867f"`,
    )
    await queryRunner.query(
      `DROP INDEX "public"."IDX_deb28c8e1a30e7b6445a873f11"`,
    )
    await queryRunner.query(`DROP TABLE "project_activities"`)
  }
}
