import { MigrationInterface, QueryRunner } from "typeorm"

export class AddInspectionQuestionsEntity1750751180639 implements MigrationInterface {
  name = "AddInspectionQuestionsEntity1750751180639"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "inspection_questions" ("id" SERIAL NOT NULL, "question_text" text NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_0bf82b858a440bf132c41bf0142" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `CREATE TABLE "inspection_answer_options" ("id" SERIAL NOT NULL, "option_text" character varying NOT NULL, "question_id" integer NOT NULL, CONSTRAINT "PK_2fb3452fba95873f042d12cd166" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_answer_options" ADD CONSTRAINT "FK_0bbe28a4d1ebe4b574b0c975118" FOREIGN KEY ("question_id") REFERENCES "inspection_questions"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
  }

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