import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE freight.wagons
      ADD COLUMN IF NOT EXISTS readiness VARCHAR(20) NOT NULL DEFAULT 'IMPORT_READY'
    `);
    await queryRunner.query(`
      CREATE INDEX IF NOT EXISTS idx_wagons_readiness
      ON freight.wagons (readiness)
      WHERE deleted_at IS NULL
    `);
  }

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