-
Notifications
You must be signed in to change notification settings - Fork 32
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
paranoidmode 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
deletedAtwhen we are callingfindAllorfindOne, can this be done automatically whenparanoindmode is enabled? We should still have a way to retrievedeletedAtif we disable paranoid mode infindAllorfindOne - 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
deletedAtwe have to use methoddestroy. When paranoid is enabled it suppose to setdeletedAtautomatically - 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,findOneand customfindByIdshould not return deleted records automatically by utilizingparanoid mode.