'use strict';

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

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

  async down(queryInterface) {
    await queryInterface.removeIndex('work_order_operation_plan', 'idx_wo_op_department');
    await queryInterface.removeColumn('work_order_operation_plan', 'department_id');
  },
};

