import { MigrationInterface, QueryRunner } from "typeorm"

export class AddIncidentImagesTable1754375051167 implements MigrationInterface {
  name = "AddIncidentImagesTable1754375051167"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "incident_images" ("id" SERIAL NOT NULL, "incident_id" integer NOT NULL, "image_url" character varying NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_7ea95e286fbc1ac9937ff32fd23" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "incident_images" ADD CONSTRAINT "FK_c1c9b31a43b4d7e19965356a02a" FOREIGN KEY ("incident_id") REFERENCES "incident_reportings"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
  }

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