Delete a single ravendb database while ravendb is running hosting other databases
Is there any way I can remove all data in a single database while RavenDB is still running, hosting other databases?
In a production environment with RavenDB hosting multiple databases for different customers, it is not acceptable to stop RavenDB in order to delete the data from a single database. Would it be necessary to custom develop a tool, at delete do开发者_如何学Ccuments individually to achieve this?
If you delete the document that describes the database then you have prevented access to it. RavenDB doesn't provide a way to actually delete the database, but the database would be shut down if you delete the document describing it. You can then delete the database directory, or back it up, according to your needs.
In version 2.0.3 (maybe even in releases before) the studio is calling the following http endpoint in order to delete a database:
/admin/databases/nameOfYourDatabase?hard-delete=true
?hard-delete=true is optional.
Based on the source code from the studio I have created this function:
public void DeleteDatabase(string name, bool hardDelete = false)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
var databaseCommands = _documentStore.DatabaseCommands;
var relativeUrl = "/admin/databases/" + name;
if (hardDelete)
relativeUrl += "?hard-delete=true";
var serverClient = databaseCommands.ForSystemDatabase() as ServerClient;
if (serverClient == null)
throw new ApplicationException("Please use a more intelligent exception here");
var httpJsonRequest = serverClient.CreateRequest("DELETE", relativeUrl);
httpJsonRequest.ExecuteRequest();
}
I want to update your solution, that are the only solution for "deleting" a database.
Actually in the new version (2.0) of RavenDB, which are still unstable, you can delete a database with the new version of the studio.
You can download it from here: http://hibernatingrhinos.com/builds/ravendb-unstable-v2.0/
I'll hope this help you aditionally to the Ayende good answer.
Best, Dario
精彩评论