'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const table = await queryInterface.describeTable('qa_master_component');
    const cols = [
      ['width_tol', 'width'],
      ['length_tol', 'length'],
      ['height_tol', 'height'],
      ['thickness_tol', 'thickness']
    ];

    for (const [col, afterCol] of cols) {
      if (!table[col]) {
        await queryInterface.addColumn('qa_master_component', col, {
          type: Sequelize.STRING(50),
          allowNull: true,
          after: afterCol
        });
      }
    }
  },

  async down(queryInterface) {
    const table = await queryInterface.describeTable('qa_master_component');
    const cols = ['width_tol', 'length_tol', 'height_tol', 'thickness_tol'];
    for (const col of cols) {
      if (table[col]) {
        await queryInterface.removeColumn('qa_master_component', col);
      }
    }
  }
};

