'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.addColumn('bom_header', 'parent_bom_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'bom_header',
        key: 'id'
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL',
      comment: 'Parent BOM header reference (for sub-assembly BOMs)'
    });

    await queryInterface.addIndex('bom_header', ['parent_bom_id'], {
      name: 'idx_bom_header_parent_bom_id'
    });
  },

  down: async (queryInterface) => {
    await queryInterface.removeIndex('bom_header', 'idx_bom_header_parent_bom_id');
    await queryInterface.removeColumn('bom_header', 'parent_bom_id');
  }
};

