'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const tableDescription = await queryInterface.describeTable('Transactions');
    
    if (!tableDescription.originalTransactionId) {
      await queryInterface.addColumn('Transactions', 'originalTransactionId', {
        type: Sequelize.INTEGER,
        allowNull: true,
        references: { model: 'Transactions', key: 'id' },
        onUpdate: 'CASCADE',
        onDelete: 'SET NULL'
      });
    }
  },

  down: async (queryInterface, Sequelize) => {
    const tableDescription = await queryInterface.describeTable('Transactions');
    
    if (tableDescription.originalTransactionId) {
      await queryInterface.removeColumn('Transactions', 'originalTransactionId');
    }
  }
};