jiangphcn commented on issue #2666: soft-deletion for database URL: https://github.com/apache/couchdb/pull/2666#issuecomment-610668810 ## Soft delete Instead of automatically and immediately removing the data and index in the database after a delete operation, soft delete restores the deleted data back to the original state after an accidental delete or undesired delete operation, up to a defined period, such as 48 hours. ### `GET /_deleted_dbs` Send a `GET` request to find a list of all the deleted databases in the {{site.data.keyword.cloudant_short_notm}} instance. *Request Headers*: ```sh Accept – application/json text/plain ``` {: codeblock} | Query parameters | Description | |------------------|-------------| | `descending` (boolean) | Return the databases in descending order by key. Default is false. | | `endkey` (json) | Stop returning databases when the specified key is reached. | | `end_key` (json) | Alias for `endkey` parameter. | | `key` (json) | Return the databases for the specified key. It can be database name or database name + timestamp.| | `limit` (number) | Limit the number of the returned databases to the specified number. | | `skip` (number) | Skip this number of databases before starting to return the results. Default is 0. | | `startkey` (json) | Return databases starting with the specified key. | | `start_key` (json) | Alias for `startkey`. | *Response Headers*: ```sh Content-Type – application/json text/plain; charset=utf-8 ``` {: codeblock} | Code | Description | |------|-------------| | `200 OK` | Request completed successfully. | | `400 Bad Request` | Bad Request. Invalid payload in request. | | `401 Unauthorized` | CouchDB Server Administrator privileges required. | | `404 NotFound` | Invalid deleted database or timestamp. | See the following example request: ```sh GET /_deleted_dbs HTTP/1.1 Accept: application/json Host: localhost:5984 ``` {: codeblock} See the following example response: ```sh HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Length: 52 Content-Type: application/json Date: Tue, 23 Mar 2020 06:57:48 GMT Server: CouchDB (Erlang/OTP) [ { "cluster": { "n": 0, "q": 0, "r": 0, "w": 0 }, "compact_running": false, "data_size": 193164408719, "db_name": "invoices", "disk_format_version": 0, "disk_size": 46114703224, "instance_start_time": "0", "purge_seq": 0, "update_seq": "981...uUQ", "doc_del_count": 5564, "doc_count": 9818541, "sizes": { "external": 193164408719, "views": 34961621142 }, "deleted": true, "timestamp": "2020-04-07T23:19:12Z" }, { "cluster": { "n": 0, "q": 0, "r": 0, "w": 0 }, "compact_running": false, "data_size": 0, "db_name": "contacts", "disk_format_version": 0, "disk_size": 0, "instance_start_time": "0", "purge_seq": 0, "update_seq": "000000000000000000000000", "doc_del_count": 0, "doc_count": 0, "sizes": { "external": 2, "views": 0 }, "deleted": true, "timestamp": "2020-04-07T23:19:02Z" }, ] ``` {: codeblock} ### `POST /_deleted_dbs` {: #post-_deleted_dbs_undelete} Send a `POST` request to restore a deleted database. Parameters: None Request Headers: ```sh Accept – application/json text/plain { "undelete": { "timestamp" : "2020-03-23T02:26:35Z", "source" : "db01", "target" : "db02" } } - "timestamp" - timestamp when database was deleted - "target" could be optional and default to the source database name. ``` {: codeblock} Response Headers: ```sh Content-Type – application/json text/plain; charset=utf-8 ``` {: codeblock} | Response JSON object | Description | |----------------------|-------------| | `ok` (boolean) | Operation status. Available in case of success. | | `error` (string) | Error type. Available if response code is 4xx. | | `reason` (string) | Error description. Available if response code is 4xx. | | Code | Message | |--------------|---------| | `200 Undeleted` | Database undeleted successfully. | | `400 Bad Request` | Bad Request. Invalid payload in request. | | `401 Unauthorized` | CouchDB Server Administrator privileges required. | | `404 NotFound` | Invalid deleted timestamp. | | `412 Precondition Failed` | Database already exists. | ### `DELETE /_deleted_dbs/{db}` {: #get-_deleted_dbs-db} Send a `DELETE` request to permanently delete the database instance which was soft-deleted with the specified timestamp. | Parameters | Description | |------------|-------------| | `timestamp` | Timestamp when database was deleted | Request Headers: ```sh Content-Type – application/json ``` {: codeblock} Response Headers: ```sh Content-Type – application/json text/plain; charset=utf-8 ``` {: codeblock} | Response JSON object | Description | |----------------------|-------------| | `ok` (boolean) | Operation status. Available in case of success. | | `error` (string) | Error type. Available if response code is 4xx. | | `reason` (string) | Error description. Available if response code is 4xx. | | Code | Message | |--------------|---------| | `200 Deleted` | Database permanently deleted successfully. | | `400 Bad Request` | Bad Request. Invalid payload in request. | | `401 Unauthorized` | CouchDB Server Administrator privileges required. | | `404 NotFound` | Invalid deleted database or timestamp. |
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
