import { MigrationInterface, QueryRunner } from "typeorm"

export class CreateCancelReason1755157230032 implements MigrationInterface {
  name = "CreateCancelReason1755157230032"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "cancel_reasons" ("id" SERIAL NOT NULL, "name" character varying(255) NOT NULL, "description" text, "is_active" boolean NOT NULL DEFAULT true, CONSTRAINT "PK_a5fed0302cd28b1bdd4fe3ef062" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `CREATE TABLE "trip_cancellations" ("id" SERIAL NOT NULL, "trip_id" bigint NOT NULL, "canceled_by" character varying(100) NOT NULL, "canceled_by_id" integer, "reason_id" integer, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_e99ed647e3a4490e211d91995ff" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "trip_cancellations" ADD CONSTRAINT "FK_b0243fcd275421a684661ecb86c" FOREIGN KEY ("reason_id") REFERENCES "cancel_reasons"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

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