import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddCustomerTruckAssignmentToBookings1832000000000 implements MigrationInterface {
  name = 'AddCustomerTruckAssignmentToBookings1832000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.bookings
        ADD COLUMN IF NOT EXISTS customer_truck_plate_number varchar(32),
        ADD COLUMN IF NOT EXISTS customer_truck_driver_name varchar(120),
        ADD COLUMN IF NOT EXISTS customer_truck_type varchar(60),
        ADD COLUMN IF NOT EXISTS customer_truck_container_number varchar(16),
        ADD COLUMN IF NOT EXISTS customer_truck_assigned_at timestamptz,
        ADD COLUMN IF NOT EXISTS customer_truck_arrived_at timestamptz
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.bookings
        DROP COLUMN IF EXISTS customer_truck_arrived_at,
        DROP COLUMN IF EXISTS customer_truck_assigned_at,
        DROP COLUMN IF EXISTS customer_truck_container_number,
        DROP COLUMN IF EXISTS customer_truck_type,
        DROP COLUMN IF EXISTS customer_truck_driver_name,
        DROP COLUMN IF EXISTS customer_truck_plate_number
    `);
  }
}
