'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const tableName = 'routing_operation';
    const columns = await queryInterface.describeTable(tableName);

    if (!columns.operation_materials_json) {
      await queryInterface.addColumn(tableName, 'operation_materials_json', {
        type: Sequelize.TEXT('long'),
        allowNull: true,
        comment: 'JSON array of material IDs selected for this routing operation'
      });
    }
  },

  async down(queryInterface) {
    const tableName = 'routing_operation';
    const columns = await queryInterface.describeTable(tableName);

    if (columns.operation_materials_json) {
      await queryInterface.removeColumn(tableName, 'operation_materials_json');
    }
  }
};

