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

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

    await queryRunner.addColumn(
      'networks',
      new TableColumn({
        name: 'code',
        type: 'varchar',
        length: '255',
        isNullable: false,
        default: "''",
      }),
    );
  }

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