If a document type is so marked, treat deletions of that document as a "soft delete." Maybe have:
var store = DocumentStore(_ => {
_.For<User>().SoftDeletes();
});
That would force Marten to add an additional column to the storage table for "deleted" and make that false by default. We would then need to intercept deletion requests and do it instead by marking the "deleted" column to true.
The DocumentMapping default query filtering would then need to set deleted = false so that normal calls to session.Query<User>() would automatically filter out soft deleted documents.
Come back with an explicit "session.Query
Come back with an explicit "session.Query().IncludeDeleted()" that would get you out of the deletions.
The .IncludeDelete() implies that this will return documents that have and _have not_ been soft deleted, right? So then would there also be a: session.Query().OnlyDeleted()?
Bad phrasing on my part. So how about:
IncludeDeleted() gets you all documents regardless of deletion status, and OnlyDeleted() does exactly what it sounds like?
Would it be beneficial to have the deleted column be a DateTime so you can see when it was deleted?
For example, deleted_at would be null if not deleted yet, or it would have the time it was deleted at if deleted.
@headdetect Hadn't thought about that, but yeah, we'll do that.
Tasking for this -- but this is only a preliminary guess jotted down just to give @nieve a head start if he still wants to do it;)
DocumentMapping.DeletionStyle = Remove/SoftDelete[SoftDelete] attribute as an alternativeIncludeDeleted(), including the compiled queryDeletedOnly(), including the compiled queryIDocumentStorage for the document type to "know" how to add the right ICall for deletionGreat stuff, will get cracking :smile:
One thing though- the "deleted" field, shouldn't it be deleted_at (nullable DateTime, null by default) as mentioned above?
@nieve I was thinking two fields, but yeah, deleted_at as a nullable field is probably easier. Another thing I've kicked around on paper is creating a new concept of an IDeleter<T> that only governs creating the SQL for doing both the delete by Id and delete by where clause. I'm seeing 4 permutations of it:
Maybe we could build out those four flavors of IDeleter, and have it determined just once per doc type and used throughout?
Most helpful comment
Bad phrasing on my part. So how about:
IncludeDeleted()gets you all documents regardless of deletion status, andOnlyDeleted()does exactly what it sounds like?