'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('gate_entry', 'received_by', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'user',
        key: 'id',
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
      comment: 'Person who received inward inspection material',
    });

    await queryInterface.addIndex('gate_entry', ['received_by'], {
      name: 'idx_gate_entry_received_by',
    });
  },

  async down(queryInterface) {
    await queryInterface.removeIndex('gate_entry', 'idx_gate_entry_received_by');
    await queryInterface.removeColumn('gate_entry', 'received_by');
  },
};

