'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const routeCardOperationTable = 'route_card_operation';
    const productionQCTable = 'production_qc';

    const rcoCols = await queryInterface.describeTable(routeCardOperationTable);
    if (!rcoCols.operator_ids) {
      await queryInterface.addColumn(routeCardOperationTable, 'operator_ids', {
        type: Sequelize.TEXT,
        allowNull: true,
        after: 'operator_id'
      });
    }

    const pqcCols = await queryInterface.describeTable(productionQCTable);
    if (!pqcCols.qc_by_ids) {
      await queryInterface.addColumn(productionQCTable, 'qc_by_ids', {
        type: Sequelize.TEXT,
        allowNull: true,
        after: 'qc_by'
      });
    }
  },

  async down(queryInterface) {
    const routeCardOperationTable = 'route_card_operation';
    const productionQCTable = 'production_qc';

    const rcoCols = await queryInterface.describeTable(routeCardOperationTable);
    if (rcoCols.operator_ids) {
      await queryInterface.removeColumn(routeCardOperationTable, 'operator_ids');
    }

    const pqcCols = await queryInterface.describeTable(productionQCTable);
    if (pqcCols.qc_by_ids) {
      await queryInterface.removeColumn(productionQCTable, 'qc_by_ids');
    }
  }
};
