'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const table = await queryInterface.describeTable('qa_master_component');
    for (let i = 1; i <= 10; i += 1) {
      const dimCol = `pb_dim_${i}`;
      const tolCol = `pb_tol_${i}`;
      if (!table[dimCol]) {
        await queryInterface.addColumn('qa_master_component', dimCol, {
          type: Sequelize.STRING(50),
          allowNull: true
        });
      }
      if (!table[tolCol]) {
        await queryInterface.addColumn('qa_master_component', tolCol, {
          type: Sequelize.STRING(50),
          allowNull: true
        });
      }
    }
  },

  async down(queryInterface) {
    const table = await queryInterface.describeTable('qa_master_component');
    for (let i = 10; i >= 1; i -= 1) {
      const tolCol = `pb_tol_${i}`;
      const dimCol = `pb_dim_${i}`;
      if (table[tolCol]) await queryInterface.removeColumn('qa_master_component', tolCol);
      if (table[dimCol]) await queryInterface.removeColumn('qa_master_component', dimCol);
    }
  }
};

