'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('bom_component', 'component_length', {
      type: Sequelize.DECIMAL(15, 3),
      allowNull: true,
      comment: 'Defaulted from material master and editable in BOM',
      after: 'component_height',
    });

    await queryInterface.addColumn('bom_component', 'component_material_grade', {
      type: Sequelize.STRING(100),
      allowNull: true,
      comment: 'Defaulted from material master and editable in BOM',
      after: 'component_thickness',
    });

    await queryInterface.sequelize.query(`
      UPDATE bom_component
      SET component_length = component_height
      WHERE component_length IS NULL AND component_height IS NOT NULL
    `);
  },

  async down(queryInterface) {
    await queryInterface.removeColumn('bom_component', 'component_material_grade');
    await queryInterface.removeColumn('bom_component', 'component_length');
  },
};
