import { MigrationInterface, QueryRunner } from "typeorm"

export class AddCustomerTreatmentPlanEntity1758782280263 implements MigrationInterface {
  name = "AddCustomerTreatmentPlanEntity1758782280263"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "customer_treatment_plan_images" ("id" SERIAL NOT NULL, "treatment_plan_id" integer NOT NULL, "plan_image" character varying, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), CONSTRAINT "PK_fd31ea2850e57a1510fda74a3e7" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `CREATE TABLE "customer_treatment_plans" ("id" SERIAL NOT NULL, "customer_id" integer NOT NULL, "comments" character varying, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_a747f9f21b506f455f91edb02f8" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "customer_treatment_plan_images" ADD CONSTRAINT "FK_5a2ed63b51774050ae3bb6f8cc1" FOREIGN KEY ("treatment_plan_id") REFERENCES "customer_treatment_plans"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "customer_treatment_plans" ADD CONSTRAINT "FK_cd64ececde55df401239c5731d3" FOREIGN KEY ("customer_id") REFERENCES "customers"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
  }

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