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

export class AddEstallerToTallerProductos1761000000000
  implements MigrationInterface
{
  public async up(queryRunner: QueryRunner): Promise<void> {
    const table = await queryRunner.getTable("taller_productos");
    const hasColumn = table?.findColumnByName("estaller");

    if (!hasColumn) {
      await queryRunner.addColumn(
        "taller_productos",
        new TableColumn({
          name: "estaller",
          type: "boolean",
          default: true,
        }),
      );
    }
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    const table = await queryRunner.getTable("taller_productos");
    const hasColumn = table?.findColumnByName("estaller");

    if (hasColumn) {
      await queryRunner.dropColumn("taller_productos", "estaller");
    }
  }
}
