'use strict';

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

    await queryInterface.addIndex('operation_name', ['department_id'], {
      name: 'idx_operation_name_department',
    });
  },

  async down(queryInterface) {
    await queryInterface.removeIndex('operation_name', 'idx_operation_name_department');
    await queryInterface.removeColumn('operation_name', 'department_id');
  },
};

