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

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

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

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