fix(fees): Avoid duplicated in advance - Phase 1 #4225
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
We recently identified a bug in the processing of events for pay in advance charges that led to some duplicated fees in the database. See #4220 for the fix of the initial bug.
On the fees table, an index named
idx_on_pay_in_advance_event_transaction_id_charge_i_16302ca167
was supposed to prevent duplicated in advance fees:The issue reside in the way Postgres handles null values in indexes. Each null value is considered a distinct value meaning the index is useless in its current form as since
charge_filter_id
is null most of the time...Goal
The main goal of the fix is to add a new set of index to really prevent duplication in the database.
The difficulty will reside in the fact that we already have duplicated values in DB and we cannot remove them as they have already impacted the customers.
The complete fix will follow these steps:
duplicated_in_advance
flag on the fees table with default value to falseDescription
This PR is the phase 1.
It adds two migrations to:
duplicated_in_advance
field to the fees table