import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Per-wagon EXPORT/IMPORT run numbers, editable from the wagon form.
 *
 * Nullable with no default: a wagon is not on a run until an operator says so.
 * Mirrors the width of trains.export_train_number / trains.import_train_number
 * (varchar 20) so the two stay comparable.
 */
export class AddWagonTrainNumbers2270000000000 implements MigrationInterface {
  name = 'AddWagonTrainNumbers2270000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.wagons
        ADD COLUMN IF NOT EXISTS export_train_number varchar(20),
        ADD COLUMN IF NOT EXISTS import_train_number varchar(20);
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.wagons
        DROP COLUMN IF EXISTS export_train_number,
        DROP COLUMN IF EXISTS import_train_number;
    `);
  }
}
