import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Consolidation is now system-managed: the backend consolidates partial-wagon
 * container bookings automatically, derived from the container quantities. The
 * `allow_consolidation` opt-in flag is therefore redundant and is dropped.
 * `consolidation_partner_id` (the actual pairing link) is unaffected.
 */
export class DropAllowConsolidation1820000000000 implements MigrationInterface {
  name = 'DropAllowConsolidation1820000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.bookings DROP COLUMN IF EXISTS allow_consolidation;`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.bookings ADD COLUMN IF NOT EXISTS allow_consolidation BOOLEAN NOT NULL DEFAULT false;`,
    );
  }
}
