'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('material_request', 'customer_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'business_partner',
        key: 'id',
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
    });

    await queryInterface.addIndex('material_request', ['customer_id'], {
      name: 'idx_material_request_customer_id',
    });
  },

  async down(queryInterface) {
    await queryInterface.removeIndex('material_request', 'idx_material_request_customer_id');
    await queryInterface.removeColumn('material_request', 'customer_id');
  },
};
