import { MigrationInterface, QueryRunner, Table, TableIndex } from "typeorm";

export class CreateTallerProductos1740052000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: "taller_productos",
        columns: [
          { name: "plu", type: "varchar", length: "24", isPrimary: true },
          { name: "desclarga", type: "varchar", length: "255" },
          {
            name: "desccorta",
            type: "varchar",
            length: "100",
            isNullable: true,
          },
          { name: "alterno", type: "varchar", length: "50", isNullable: true },
          {
            name: "precio",
            type: "decimal",
            precision: 12,
            scale: 2,
            default: 0,
          },
          { name: "pagaiva", type: "boolean", default: false },
          { name: "iva", type: "decimal", precision: 5, scale: 2, default: 0 },
          { name: "es_servicio", type: "boolean", default: false },
          { name: "usainventario", type: "boolean", default: true },
          {
            name: "created_at",
            type: "timestamp",
            default: "CURRENT_TIMESTAMP",
          },
          {
            name: "updated_at",
            type: "timestamp",
            default: "CURRENT_TIMESTAMP",
            onUpdate: "CURRENT_TIMESTAMP",
          },
        ],
      }),
      true,
    );

    await queryRunner.createIndex(
      "taller_productos",
      new TableIndex({
        name: "IDX_taller_productos_plu",
        columnNames: ["plu"],
      }),
    );

    await queryRunner.createIndex(
      "taller_productos",
      new TableIndex({
        name: "IDX_taller_productos_desclarga",
        columnNames: ["desclarga"],
      }),
    );

    await queryRunner.createIndex(
      "taller_productos",
      new TableIndex({
        name: "IDX_taller_productos_alterno",
        columnNames: ["alterno"],
      }),
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable("taller_productos", true);
  }
}
