import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';

export class AddMinimumSwapValueToTokens1787000000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    const table = await queryRunner.getTable('tokens');
    if (table?.findColumnByName('minimum_swap_value')) {
      return;
    }

    await queryRunner.addColumn(
      'tokens',
      new TableColumn({
        name: 'minimum_swap_value',
        type: 'double',
        isNullable: true,
        default: null,
      }),
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    const table = await queryRunner.getTable('tokens');
    if (table?.findColumnByName('minimum_swap_value')) {
      await queryRunner.dropColumn('tokens', 'minimum_swap_value');
    }
  }
}
