import { MigrationInterface, QueryRunner } from "typeorm"

export class AddEntityForDriverFleetHistory1755667598354 implements MigrationInterface {
  name = "AddEntityForDriverFleetHistory1755667598354"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "driver_fleet_history" ("id" SERIAL NOT NULL, "fleet_id" integer, "driver_id" integer, "assigned_at" TIMESTAMP NOT NULL DEFAULT now(), "released_at" TIMESTAMP, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_4f93795f9f4686f7341fb603e70" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "driver_fleet_history" ADD CONSTRAINT "FK_3313d8cc97696cb8fbf7e344ffb" FOREIGN KEY ("fleet_id") REFERENCES "fleet_operations"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "driver_fleet_history" ADD CONSTRAINT "FK_b05df2547708c153bdfd52ee146" FOREIGN KEY ("driver_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 "driver_fleet_history" DROP CONSTRAINT "FK_b05df2547708c153bdfd52ee146"`,
    )
    await queryRunner.query(
      `ALTER TABLE "driver_fleet_history" DROP CONSTRAINT "FK_3313d8cc97696cb8fbf7e344ffb"`,
    )
    await queryRunner.query(`DROP TABLE "driver_fleet_history"`)
  }
}
