Fork me on GitHub

what's the best practice for "deleting" items and later being able to query them and restore them. In SQL you would record a deleted timestamp and use a WHERE deleted IS NULL in all queries... it seems in datomic one should just retract the entity?


but it seems the pulling deleted entities is somewhat cumbersome, you need to get the deletion tx instant and pull from db that is as-of one millisecond before the deletion


and I guess reinstating the entity would be to reassert all the facts?


A 'deleted' marker like that seems different to a retraction, so why not use the marker? Would be more convenient. Also see two kinds of time here:


That raises good points


But the down side is that every query would need to filter out deleted items in where clause


True enough. And you might want it to be an instant in 'event time' rather than a boolean. Also you could have another entity with all the same attributes and then the 'deleted' attribute as well. More work do do at the time of deletion (shuffling it into another entity), but then you wouldn't have to filter out for everyday queries.


Every query has to do the same in SQL


That is true, and I've always disliked it... you can work around it in SQL by using views.


@tatut suggestion: create a new entity type like {:retraction/before tx, :retraction/eid eid}. When you retract your entity, invoke a transaction function that creates the "retraction" entity. Under :retraction/before, store the tx of the t of the in-transaction database. You can later use it to restore the db as-of the time of deletion. Under :retraction/eid store the entity ID of the retracted entity.

👍 4

this would be out of the way of your usual queries and gives you the ability to find it again, reference the "retraction" in other context etc.


I'd only do it if I have to, because usually a history or log query does the job if I want to restore something deleted