Transactions are registered but sometimes the entire amount or part of it is returned to the other party. Support this event in the application gives more meaning to the transactions, improving traceability.
To solve this problem, we need to change the transaction table adapting existing columns and adding extra ones, but being careful to keep the data consistent. The current table structure solves a similar problem, the transfer of money between accounts, but the existing column is very specific to transfer. It can be redesigned to be more generic.
Create columns:
[ ] linked_transaction (foreign key to transaction)
[ ] link_type [TRANSFER, REFUND]
Migrate existing data:
[ ] Given the list of transactions with account_transfer not null, order by amount and date_transaction. Related transfer transactions will be grouped in pairs.
[ ] For every iteration, get two records at the same time and exchange their ids using the new column linked_transaction.
[ ] Change the link_type of these transactions to TRANSFER
[ ] Remove column account_transfer from the table transaction
Transactions are registered but sometimes the entire amount or part of it is returned to the other party. Support this event in the application gives more meaning to the transactions, improving traceability.
To solve this problem, we need to change the transaction table adapting existing columns and adding extra ones, but being careful to keep the data consistent. The current table structure solves a similar problem, the transfer of money between accounts, but the existing column is very specific to transfer. It can be redesigned to be more generic.
Create columns:
linked_transaction
(foreign key to transaction)link_type
[TRANSFER
,REFUND
]Migrate existing data:
account_transfer
not null, order byamount
anddate_transaction
. Related transfer transactions will be grouped in pairs.linked_transaction
.link_type
of these transactions toTRANSFER
account_transfer
from the tabletransaction