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

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

    await queryRunner.addColumn(
      'wallets',
      new TableColumn({
        name: 'name',
        type: 'varchar',
        length: '100',
        isNullable: false,
        default: "'Wallet'",
      }),
    );
  }

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