AccountRow: have just 1 amount column

Current Situation

At the moment the AccountRow table has this definition:

  `amount_in`  decimal(10,2) NOT NULL DEFAULT 0.00,
  `amount_out` decimal(10,2) NOT NULL DEFAULT 0.00,

Historical intention:

  • Originally, these amount_in/amount_out allowed to manage a membership fee PLUS its PayPal fee in a single row.
  • (↑ From #110 (comment 2033573144) )
  • Anyway, since many years we manage PayPal fees differently (in a dedicated row).

Current concerns:

  • it's not possible for human beings to audit the correctness of these two fields since the frontend never shows these two fields separately
  • both fields are supposed to store absolute amounts and be unsigned. Instead, both allow negative numbers.
  • both fields are never used together (in production SELECT * FROM account_rows WHERE amount_in != 0.0 AND amount_out != 0.0; returns zero results - so probably one field signed is just enough - instead of two signed fields)
  • we have also some inconsistencies in production where the amount_in sometime is negative, sometime is positive (this is not a crucial problem, since sums still makes sense. But it's a good indication of the potential problem)

Proposed Solution

We can refactor the table structure of the AccountRow entity to be just like this:

  `amount`  decimal(10,2) NOT NULL DEFAULT 0.00,

Benefits:

  • the frontend 1:1 reflects storage and we drop possibilities to introduce amount weirdness
  • simpler business logic (a negative number is just a number, a positive number is just a number, the sum just sums)
  • no risks of populating both IN/OUT by mistake
  • is simpler in terms of database management: the database administrator (DBA) does not have to design and introduce twice as many indexes, to speedup SQL queries over amounts greater than / less than something

Challenges:

  • How-to calculate incomes and expenses after this change?
    • → We can just SELECT amount WHERE amount > 0 or SELECT amount WHERE AMOUNT < 0 (even simpler than before)
Edited by Valerio Bozzolan