import { MigrationInterface, QueryRunner } from "typeorm"

export class AddIntermediateStopTable1752570759720 implements MigrationInterface {
  name = "AddIntermediateStopTable1752570759720"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "trip_intermediate_stops" ("id" SERIAL NOT NULL, "trip_id" integer, "stop_address" character varying, "duration" character varying, "notes" character varying, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_504e0803688607383d5a2c3a3e9" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "trip_intermediate_stops" ADD CONSTRAINT "FK_86772b18ea6b895d920c7617913" FOREIGN KEY ("trip_id") REFERENCES "trips"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
  }

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