'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.addColumn('sales_invoice', 'company_bank_detail_id', {
      type: Sequelize.INTEGER,
      allowNull: true,
      references: {
        model: 'company_bank_detail',
        key: 'id'
      },
      onUpdate: 'CASCADE',
      onDelete: 'SET NULL'
    });
    await queryInterface.addColumn('sales_invoice', 'bank_account_holder_name', {
      type: Sequelize.STRING(200),
      allowNull: true
    });
    await queryInterface.addColumn('sales_invoice', 'bank_name', {
      type: Sequelize.STRING(200),
      allowNull: true
    });
    await queryInterface.addColumn('sales_invoice', 'bank_account_no', {
      type: Sequelize.STRING(50),
      allowNull: true
    });
    await queryInterface.addColumn('sales_invoice', 'bank_branch', {
      type: Sequelize.STRING(200),
      allowNull: true
    });
    await queryInterface.addColumn('sales_invoice', 'bank_ifsc_code', {
      type: Sequelize.STRING(20),
      allowNull: true
    });
    await queryInterface.addIndex('sales_invoice', ['company_bank_detail_id']);
  },

  async down(queryInterface) {
    await queryInterface.removeIndex('sales_invoice', ['company_bank_detail_id']);
    await queryInterface.removeColumn('sales_invoice', 'bank_ifsc_code');
    await queryInterface.removeColumn('sales_invoice', 'bank_branch');
    await queryInterface.removeColumn('sales_invoice', 'bank_account_no');
    await queryInterface.removeColumn('sales_invoice', 'bank_name');
    await queryInterface.removeColumn('sales_invoice', 'bank_account_holder_name');
    await queryInterface.removeColumn('sales_invoice', 'company_bank_detail_id');
  }
};

