Skip to content

[$100] Refactor soft-deleting #132

Closed
@maxceem

Description

@maxceem

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 adding paranoid: 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 calling findAll or findOne, can this be done automatically when paranoind mode is enabled? We should still have a way to retrieve deletedAt if we disable paranoid mode in findAll or findOne
  • 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 method destroy. When paranoid is enabled it suppose to set deletedAt 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 custom findById should not return deleted records automatically by utilizing paranoid mode.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions