import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Yard soft-delete now appends `@<epoch-ms>` to the unique code (SEBETA →
 * SEBETA@1755612345678) so the name can be reused by a new yard while
 * UQ_yards_code still spans soft-deleted rows. varchar(20) can't hold long
 * codes plus the 14-char suffix, so widen to 40.
 */
export class WidenYardCodeForSoftDeleteSuffix2390000000000 implements MigrationInterface {
  name = 'WidenYardCodeForSoftDeleteSuffix2390000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "freight"."yards" ALTER COLUMN "code" TYPE varchar(40)`,
    );
  }

  public async down(): Promise<void> {
    // Narrowing would fail on suffixed codes; keep 40.
  }
}
