'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.changeColumn('general_dc_item', 'material_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: { model: 'material', key: 'id' },
      onUpdate: 'CASCADE',
      onDelete: 'RESTRICT'
    });

    await queryInterface.changeColumn('general_dc_item', 'uom_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: { model: 'uom', key: 'id' },
      onUpdate: 'CASCADE',
      onDelete: 'RESTRICT'
    });

    await queryInterface.changeColumn('general_receipt_item', 'material_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: { model: 'material', key: 'id' },
      onUpdate: 'CASCADE',
      onDelete: 'RESTRICT'
    });

    await queryInterface.changeColumn('general_receipt_item', 'uom_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: { model: 'uom', key: 'id' },
      onUpdate: 'CASCADE',
      onDelete: 'RESTRICT'
    });
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.changeColumn('general_receipt_item', 'uom_id', {
      type: Sequelize.INTEGER,
      allowNull: false,
      references: { model: 'uom', key: 'id' },
      onUpdate: 'CASCADE',
      onDelete: 'RESTRICT'
    });

    await queryInterface.changeColumn('general_receipt_item', 'material_id', {
      type: Sequelize.INTEGER,
      allowNull: false,
      references: { model: 'material', key: 'id' },
      onUpdate: 'CASCADE',
      onDelete: 'RESTRICT'
    });

    await queryInterface.changeColumn('general_dc_item', 'uom_id', {
      type: Sequelize.INTEGER,
      allowNull: false,
      references: { model: 'uom', key: 'id' },
      onUpdate: 'CASCADE',
      onDelete: 'RESTRICT'
    });

    await queryInterface.changeColumn('general_dc_item', 'material_id', {
      type: Sequelize.INTEGER,
      allowNull: false,
      references: { model: 'material', key: 'id' },
      onUpdate: 'CASCADE',
      onDelete: 'RESTRICT'
    });
  }
};
