'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('purchase_order_item', 'storage_location_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        // Use the actual table name for the foreign key reference
        model: 'storage_location',
        key: 'id'
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
      comment: 'Default storage location for this PO line (copied from Material, editable by user)'
    });

    await queryInterface.addIndex('purchase_order_item', ['storage_location_id']);
  },

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

