typeorm-helpers icon indicating copy to clipboard operation
typeorm-helpers copied to clipboard

Deleted entities not tracked in history

Open harveyappleton opened this issue 4 years ago • 6 comments

When an entity is soft deleted, the history log does not show this.

(See point 5 on this comment for more info on soft delete event behaviour: https://github.com/typeorm/typeorm/issues/534#issuecomment-535416895)

harveyappleton avatar Jul 20 '21 17:07 harveyappleton

OK updates:

  1. Calling .delete() or .softDelete() does not emit an action that history can subscribe to, hence the history log not showing this. Calling .remove() or .softRemove() does emit an action.

  2. Calling .softRemove() actually emits an update action, not a delete action. (See comment linked above). Not sure how you want to handle this @anchan828 ? If someone were to perform: create entity -> soft delete it -> recover it - what should history log show? CREATED, UPDATED, UPDATED? or CREATED, DELETED, RECOVERED?

harveyappleton avatar Jul 20 '21 17:07 harveyappleton

Hi @harveyappleton,

1

The history pacakge supports ActiveRecord patterns. .delete() and .softDelete() are for manager and repository patterns, right? At the moment, I can't support this unless the Subscriber can also pass entities via delete and softDelete 😔.

2

I can't support this unless the Subscriber can also pass delete date object... https://github.com/typeorm/typeorm/issues/6327

anchan828 avatar Jul 21 '21 04:07 anchan828

  1. It seems to be working for me, and I am using repository pattern not ActiveRecord pattern, so that's good! I think the .delete() and .softDelete() methods don't emit events, but the remove equivalents do.. here's an excerpt from the typescript definition files for the entity manager:
     * Deletes entities by a given condition(s).
     * Unlike save method executes a primitive operation without cascades, relations and other operations included.
     * Executes fast and efficient DELETE query.
     * Does not check if entity exist in the database.
     * Condition(s) cannot be empty.
     */
  1. Ah ok, for now then I guess it can only be CREATED, UPDATED, UPDATED until we can get the deleted_at column value into the subscriber?

harveyappleton avatar Jul 23 '21 11:07 harveyappleton

Thanks for the info.

  1. My understanding is that Delete only deletes by a given condition, so it may not hold the entity. What this means is that you may have to use .find to get the entity to create the History from original entity.

  2. Maybe yes. You can create an UPDATED event, but I think the deleted_at will be saved as null.

anchan828 avatar Jul 26 '21 13:07 anchan828

Solving this problem seems to be very difficult. I can’t come up with any good ideas, So I may need to change my perspective. 🤔

anchan828 avatar Jul 26 '21 13:07 anchan828

Thanks for awesome lib guys. Just wanted to mention that ability to emit events on softDelete looks quite valuable and desired from my perspective too)

mopcweb avatar Jun 20 '22 15:06 mopcweb

Hi, Sorry, I already don't use and don't maintain the history package. So I removed the package. I can't state clearly, but if you search for a similar package, you might try to use that one. Thanks for using it.

anchan828 avatar Dec 04 '22 07:12 anchan828