'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('request_for_quotation_item', 'vendor_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'business_partner',
        key: 'id'
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
      comment: 'Preferred vendor for this item (from material master)'
    });

    await queryInterface.addIndex('request_for_quotation_item', ['vendor_id']);
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.removeIndex('request_for_quotation_item', ['vendor_id']);
    await queryInterface.removeColumn('request_for_quotation_item', 'vendor_id');
  }
};

