'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('material_issue_item', 'material_request_item_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'material_request_item',
        key: 'id'
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
      comment: 'Link to the originating material_request_item (for MR-based issues)'
    });

    await queryInterface.addIndex('material_issue_item', ['material_request_item_id']);
  },

  async down(queryInterface) {
    await queryInterface.removeIndex('material_issue_item', ['material_request_item_id']);
    await queryInterface.removeColumn('material_issue_item', 'material_request_item_id');
  }
};


