-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDoc-3064 Add the DeleteRevisionsOperation
- Loading branch information
1 parent
a1dfdf5
commit b0ab9e8
Showing
7 changed files
with
317 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...ent-extensions/revisions/client-api/operations/delete-revisions.dotnet.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 date of the range for revisions to delete (inclusive). | | ||
| **to** | `DateTime` | The end date of the range for 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) |
192 changes: 192 additions & 0 deletions
192
...ocumentation.Samples/DocumentExtensions/Revisions/ClientAPI/Operations/DeleteRevisions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
} | ||
} | ||
} |