Description
We are using soft-deleting in the code. So when a record is deleted we don't delete it for real, but just set deletedAt
and later we treat records with deletedAt
not null as deleted and should never return it.
sequalize
already has support for this feature automatically called paranoid mode. But in our code base we are re-implemented the same functionality manually. So we have to always remember about it, and should always manually exclude deleted records in each place where we make requests. This is very easy to forget, and in fact we already had such issue when during implementing script for indexing data from ES to DB the member didn't notice it and indexed deleted records. See how it was fixed after.
We have to reimplement soft-deleting by utilizing paranoid mode of the equalize and remove our custom logic. Some steps to do which I can see:
- enable
paranoid
mode for each model by addingparanoid: true, deletedAt: 'deletedAt'
to each model. - remove all the custom logic to filter deleted records like this
{ deletedAt: null }
https://github.com/topcoder-platform/taas-apis/blob/dev/src/services/JobService.js#L414-L416 - at the moment we have to manually exclude
deletedAt
when we are callingfindAll
orfindOne
, can this be done automatically whenparanoind
mode is enabled? We should still have a way to retrievedeletedAt
if we disable paranoid mode infindAll
orfindOne
- update logic for deleting records like this one https://github.com/topcoder-platform/taas-apis/blob/dev/src/services/JobService.js#L283. Instead of setting
deletedAt
we have to use methoddestroy
. When paranoid is enabled it suppose to setdeletedAt
automatically - is there anything else what we should fix to make soft-deleting work automatically?
- at the end, all the equalize methods which we are using like
findAll
,findOne
and customfindById
should not return deleted records automatically by utilizingparanoid mode
.