import { MigrationInterface, QueryRunner } from "typeorm"

export class AddEntityForTripTimeline1763716614033 implements MigrationInterface {
  name = "AddEntityForTripTimeline1763716614033"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "trip_timeline_history" ("id" SERIAL NOT NULL, "trip_id" integer NOT NULL, "status" character varying NOT NULL, "previous_status" character varying, "changed_by_id" integer, "created_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_f36689b7e52cf7f07f62f2b6bf7" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "trip_timeline_history" ADD CONSTRAINT "FK_63e24ab44c1e1d5f0181903c931" FOREIGN KEY ("trip_id") REFERENCES "trips"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "trip_timeline_history" ADD CONSTRAINT "FK_148cc270dd78518f5398eb02dc8" FOREIGN KEY ("changed_by_id") REFERENCES "team_members"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

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