Fork me on GitHub
#datomic
<
2019-11-27
>
tatut08:11:03

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?

tatut08:11:56

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

tatut08:11:18

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

cjmurphy09:11:12

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: https://vvvvalvalval.github.io/posts/2017-07-08-Datomic-this-is-not-the-history-youre-looking-for.html

tatut10:11:00

That raises good points

tatut10:11:27

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

cjmurphy10:11:32

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.

ghadi14:11:00

Every query has to do the same in SQL

tatut05:11:13

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

leongrapenthin12:11:50

@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
leongrapenthin12:11:03

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.

leongrapenthin12:11:25

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