Skip to content

Commit

Permalink
Merge pull request #1937 from Danielle9897/RDoc-3064-deleteRevisionsO…
Browse files Browse the repository at this point in the history
…peration

RDoc-3064 Add the DeleteRevisionsOperation
  • Loading branch information
ppekrol authored Nov 12, 2024
2 parents e85ea27 + 8a7c4a8 commit 88b59db
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

* In this page:
* [Why use operations](../../client-api/operations/what-are-operations#why-use-operations)
* [How operations work](../../client-api/operations/what-are-operations#how-operations-work)
<br>
* [How operations work](../../client-api/operations/what-are-operations#how-operations-work)
* **Operation types**:
* [Common operations](../../client-api/operations/what-are-operations#common-operations)
* [Maintenance operations](../../client-api/operations/what-are-operations#maintenance-operations)
Expand Down Expand Up @@ -256,6 +255,7 @@

* **Revisions**:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ConfigureRevisionsOperation](../../document-extensions/revisions/client-api/operations/configure-revisions)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [DeleteRevisionsOperation](../../document-extensions/revisions/client-api/operations/delete-revisions)

* **Sorters**:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [PutSortersOperation](../../client-api/operations/maintenance/sorters/put-sorter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* In this page:
* [Why use operations](../../client-api/operations/what-are-operations#why-use-operations)
* [How operations work](../../client-api/operations/what-are-operations#how-operations-work)
<br>
* __Operation types__:
* [Common operations](../../client-api/operations/what-are-operations#common-operations)
* [Maintenance operations](../../client-api/operations/what-are-operations#maintenance-operations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* In this page:
* [Why use operations](../../client-api/operations/what-are-operations#why-use-operations)
* [How operations work](../../client-api/operations/what-are-operations#how-operations-work)
<br>
* **Operation types**:
* [Common operations](../../client-api/operations/what-are-operations#common-operations)
* [Maintenance operations](../../client-api/operations/what-are-operations#maintenance-operations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* In this page:
* [Why use operations](../../client-api/operations/what-are-operations#why-use-operations)
* [How operations work](../../client-api/operations/what-are-operations#how-operations-work)
<br>
* **Operation types**:
* [Common operations](../../client-api/operations/what-are-operations#common-operations)
* [Maintenance operations](../../client-api/operations/what-are-operations#maintenance-operations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@
"Key": "client-api/operations/revisions/get-revisions"
}
]
},
{
"Path": "delete-revisions.markdown",
"Name": "Delete Revisions",
"DiscussionId": "f447c943-de2f-4f55-bec4-625dd8e4094a",
"Mappings": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Delete Revisions Operation
---

{NOTE: }

* Use `DeleteRevisionsOperation` to delete document revisions.
The document itself is not deleted, only its revisions will be deleted, as specified by the operation's params.

* Existing revisions will be deleted regardless of the current [revisions settings](../../../../studio/database/settings/document-revisions),
even if these settings are disabled.

* When working with a secure server:
* The delete revisions action will be logged in the [audit log](../../../../server/security/audit-log/audit-log).
* This operation is only available for a client certificate with a [security clearance](../../../../server/security/authorization/security-clearance-and-permissions) of _DatabaseAdmin_ or higher.

* By default, the operation will be applied to the [default database](../../../../client-api/setting-up-default-database).
To operate on a different database see [switch operations to different database](../../../../client-api/operations/how-to/switch-operations-to-a-different-database).

* In this page:
* [Delete all revisions - single document](../../../../document-extensions/revisions/client-api/operations/delete-revisions#delete-all-revisions---single-document)
* [Delete revisions - multiple documents](../../../../document-extensions/revisions/client-api/operations/delete-revisions#delete-revisions---multiple-documents)
* [Delete revisions by time frame](../../../../document-extensions/revisions/client-api/operations/delete-revisions#delete-revisions-by-time-frame)
* [Delete revisions by change vectors](../../../../document-extensions/revisions/client-api/operations/delete-revisions#delete-revisions-by-change-vectors)
* [Syntax](../../../../document-extensions/revisions/client-api/operations/delete-revisions#syntax)

{NOTE/}

---

{PANEL: Delete all revisions - single document}

In this example, we delete ALL revisions of a document.
Both types of revisions, those resulting from the [revisions settings](../../../../studio/database/settings/document-revisions) and those generated manually via
[force revision creation](../../../../document-extensions/revisions/overview#force-revision-creation), will be deleted.

{CODE-TABS}
{CODE-TAB:csharp:Sync delete_revisions_1@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}
{CODE-TAB:csharp:Async delete_revisions_1_async@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}
{CODE-TABS/}

{PANEL/}

{PANEL: Delete revisions - multiple documents}

You can specify multiple documents from which to delete revisions.

{CODE-TABS}
{CODE-TAB:csharp:Sync delete_revisions_2@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}
{CODE-TAB:csharp:Async delete_revisions_2_async@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}
{CODE-TABS/}

{PANEL/}

{PANEL: Delete revisions by time frame}

You can specify a time frame from which to delete revisions.
Only revisions that were created within that time frame (inclusive) will be deleted.
The time should be specified in UTC.

{CODE-TABS}
{CODE-TAB:csharp:Sync delete_revisions_3@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}
{CODE-TAB:csharp:Async delete_revisions_3_async@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}
{CODE-TABS/}

{PANEL/}

{PANEL: Delete revisions by change vectors}

Each revision has its own unique [change vector](../../../../document-extensions/revisions/client-api/session/loading#get-revisions-by-change-vector).
You can specify which revisions to delete by providing their corresponding change vectors.
No exception is thrown if a change vector doesn’t match any revision.

{CODE-TABS}
{CODE-TAB:csharp:Sync delete_revisions_4@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}
{CODE-TAB:csharp:Async delete_revisions_4_async@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}
{CODE-TABS/}

{PANEL/}

{PANEL: Syntax}

{CODE:csharp syntax_1@DocumentExtensions\Revisions\ClientAPI\Operations\DeleteRevisions.cs /}

| Parameter | Type | Description |
|---------------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **documentId** | `string` | The ID of the document whose revisions you want to delete. |
| **documentIds** | `List<string>` | A list of document IDs whose revisions you want to delete. |
| **removeForceCreatedRevisions** | `bool` | `true` - Include [force-created revisions](../../../../document-extensions/revisions/overview#force-revision-creation) in the deletion.<br>`false` - Exclude force-created revisions. |
| **from** | `DateTime` | The start of the date range for the revisions to delete (inclusive). |
| **to** | `DateTime` | The end of the date range for the revisions to delete (inclusive). |
| **revisionsChangeVectors** | `List<string>` | A list of change vectors corresponding to the revisions that you want to delete. |

{PANEL/}

## Related Articles

### Document Extensions

* [Revisions Overview](../../../../document-extensions/revisions/overview)
* [Revert Revisions](../../../../document-extensions/revisions/revert-revisions)
* [Revisions and Other Features](../../../../document-extensions/revisions/revisions-and-other-features)
* [Revisions: API Overview](../../../../document-extensions/revisions/client-api/overview)
* [Session: Loading Revisions](../../../../document-extensions/revisions/client-api/session/loading)
* [Session: Including Revisions](../../../../document-extensions/revisions/client-api/session/including)
* [Session: Counting Revisions](../../../../document-extensions/revisions/client-api/session/counting)

### Client API

* [What Are Operations](../../../../client-api/operations/what-are-operations)
* [Switch Operation Database](../../../../client-api/operations/how-to/switch-operations-to-a-different-database)
* [Setting Up a Default Database](../../../../client-api/setting-up-default-database)

### Studio

* [Settings: Document Revisions](../../../../studio/database/settings/document-revisions)
* [Document Extensions: Revisions](../../../../studio/database/document-extensions/revisions)
* [Manage Database Group](../../../../studio/database/settings/manage-database-group)
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Raven.Client;
using Raven.Client.Documents;
using Raven.Client.Documents.Operations.Revisions;
using Xunit;

namespace Raven.Documentation.Samples.DocumentExtensions.Revisions.ClientAPI.Operations
{
public class DeleteRevisions
{
public DeleteRevisions()
{
using (var store = new DocumentStore())
{
#region delete_revisions_1
// Define the delete revisions operation:

// Delete ALL existing revisions for document "orders/830-A"
var deleteRevisionsOp = new DeleteRevisionsOperation(documentId: "orders/830-A",
// Revisions that were created manually will also be removed
removeForceCreatedRevisions: true);

// Execute the operation by passing it to Maintenance.Send
var numberOfRevisionsDeleted = store.Maintenance.Send(deleteRevisionsOp);

// Running the above code on RavenDB's sample data results in the removal of 29 revisions
Assert.Equal(29, numberOfRevisionsDeleted.TotalDeletes);
#endregion
}

using (var store = new DocumentStore())
{
#region delete_revisions_2
// Delete existing revisions for the specified documents
var deleteRevisionsOp = new DeleteRevisionsOperation(
documentIds: new List<string>() { "orders/829-A", "orders/828-A", "orders/827-A" },
// Revisions that were created manually will Not be removed
removeForceCreatedRevisions: false);

var numberOfRevisionsDeleted = store.Maintenance.Send(deleteRevisionsOp);

// Running the above on RavenDB's sample data results in the removal of 19 revisions
Assert.Equal(19, numberOfRevisionsDeleted.TotalDeletes);
#endregion
}

using (var store = new DocumentStore())
{
#region delete_revisions_3
var deleteFrom = DateTime.Parse("2018-07-27T09:11:52.0Z");
var deleteTo = DateTime.Parse("2018-07-27T09:11:54.0Z");

// Delete existing revisions within the specified time frame
var deleteRevisionsOp =
new DeleteRevisionsOperation(documentId: "orders/826-A", from: deleteFrom, to: deleteTo);

var numberOfRevisionsDeleted = store.Maintenance.Send(deleteRevisionsOp);
#endregion
}

using (var store = new DocumentStore())
{
using (var session = store.OpenSession())
{
#region delete_revisions_4
// Get the change-vectors for the revisions of the specified document
var revisionsChangeVectors = session.Advanced.Revisions
.GetMetadataFor("orders/825-A")
.Select(m => m.GetString(Constants.Documents.Metadata.ChangeVector))
.ToList();

// Delete the revisions by their change-vector
var revisionToDelete =
new List<string>() { revisionsChangeVectors[0], revisionsChangeVectors[1] };

var deleteRevisionsOp =
new DeleteRevisionsOperation(documentId: "orders/825-A", revisionToDelete);

var numberOfRevisionsDeleted = store.Maintenance.Send(deleteRevisionsOp);
#endregion
}
}
}

public async Task ConfigRevisionsAsync()
{
using (var store = new DocumentStore())
{
#region delete_revisions_1_async
// Define the delete revisions operation:

// Delete ALL existing revisions for document "orders/830-A"
var deleteRevisionsOp = new DeleteRevisionsOperation(documentId: "orders/830-A",
// Revisions that were created manually will also be removed
removeForceCreatedRevisions: true);

// Execute the operation by passing it to Maintenance.SendAsync
var numberOfRevisionsDeleted = await store.Maintenance.SendAsync(deleteRevisionsOp);

// Running the above code on RavenDB's sample data results in the removal of 29 revisions
Assert.Equal(29, numberOfRevisionsDeleted.TotalDeletes);
#endregion
}

using (var store = new DocumentStore())
{

#region delete_revisions_2_async
// Delete existing revisions for the specified documents
var deleteRevisionsOp = new DeleteRevisionsOperation(
documentIds: new List<string>() { "orders/829-A", "orders/828-A", "orders/827-A" },
// Revisions that were created manually will Not be removed
removeForceCreatedRevisions: false);

var numberOfRevisionsDeleted = await store.Maintenance.SendAsync(deleteRevisionsOp);

// Running the above on RavenDB's sample data results in the removal of 19 revisions
Assert.Equal(19, numberOfRevisionsDeleted.TotalDeletes);
#endregion
}

using (var store = new DocumentStore())
{
#region delete_revisions_3_async
var deleteFrom = DateTime.Parse("2018-07-27T09:11:52.0Z");
var deleteTo = DateTime.Parse("2018-07-27T09:11:54.0Z");

// Delete existing revisions within the specified time frame
var deleteRevisionsOp =
new DeleteRevisionsOperation(documentId: "orders/826-A", from: deleteFrom, to: deleteTo);

var numberOfRevisionsDeleted = await store.Maintenance.SendAsync(deleteRevisionsOp);
#endregion
}

using (var store = new DocumentStore())
{
using (var asyncSession = store.OpenAsyncSession())
{
#region delete_revisions_4_async
// Get the change-vectors for the revisions of the specified document
var metadata = await asyncSession.Advanced.Revisions
.GetMetadataForAsync("orders/825-A");

var revisionsChangeVectors = metadata
.Select(m => m.GetString(Constants.Documents.Metadata.ChangeVector))
.ToList();

// Delete the revisions by their change-vector
var revisionToDelete =
new List<string>() { revisionsChangeVectors[0], revisionsChangeVectors[1] };

var deleteRevisionsOp =
new DeleteRevisionsOperation(documentId: "orders/825-A", revisionToDelete);

var numberOfRevisionsDeleted = await store.Maintenance.SendAsync(deleteRevisionsOp);
#endregion
}
}
}
}

public class Syntax
{
public interface IFoo
{
/*
#region syntax_1
Available overloads:
====================
public DeleteRevisionsOperation(string documentId,
bool removeForceCreatedRevisions = false);
public DeleteRevisionsOperation(string documentId,
DateTime? from, DateTime? to, bool removeForceCreatedRevisions = false);
public DeleteRevisionsOperation(List<string> documentIds,
bool removeForceCreatedRevisions = false);
public DeleteRevisionsOperation(List<string> documentIds,
DateTime? from, DateTime? to, bool removeForceCreatedRevisions = false);
public DeleteRevisionsOperation(string documentId,
List<string> revisionsChangeVectors, bool removeForceCreatedRevisions = false);
#endregion
*/
}
}
}

0 comments on commit 88b59db

Please sign in to comment.