'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('general_dc_item', 'machine_work', {
      type: Sequelize.STRING(500),
      allowNull: true
    });

    await queryInterface.addColumn('general_receipt_item', 'machine_work', {
      type: Sequelize.STRING(500),
      allowNull: true
    });

    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'
    });

    await queryInterface.removeColumn('general_receipt_item', 'machine_work');
    await queryInterface.removeColumn('general_dc_item', 'machine_work');
  }
};
