import { MigrationInterface, QueryRunner } from "typeorm"

export class AddVehicleMaintenanceEntity1749127390911 implements MigrationInterface {
  name = "AddVehicleMaintenanceEntity1749127390911"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "vehicle_maintenances" ("id" SERIAL NOT NULL, "fleet_id" integer NOT NULL, "maintenance_type" character varying NOT NULL, "description" text, "maintenance_date" date NOT NULL, "cost" double precision NOT NULL DEFAULT '0', "performed_by" character varying, "status" character varying, "next_scheduled_maintenance" date, "document_file" character varying, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_300f16840b4f0bd81303a594f79" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "vehicle_maintenances" ADD CONSTRAINT "FK_5d72db8d809b457a917e5f86cff" FOREIGN KEY ("fleet_id") REFERENCES "fleet_operations"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

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