Skip to content

Commit

Permalink
#423 Can now delete a database via mlDeleteDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Jan 31, 2019
1 parent 3404a77 commit bd7f43c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class MarkLogicPlugin implements Plugin<Project> {
project.task("mlClearSchemasDatabase", type: ClearSchemasDatabaseTask, group: dbGroup, description: "Deletes all documents in the schemas database. " +
"Note that this includes those created via the deployment of resources such as temporal collections and view schemas. You may want to use mlDeleteUserSchemas instead.")
project.task("mlClearTriggersDatabase", type: ClearTriggersDatabaseTask, group: dbGroup, description: "Deletes all documents in the triggers database")
project.task("mlDeleteDatabase", type: DeleteDatabaseTask, group: dbGroup, description: "Delete a database along with all of its forests and any replicas; requires -Pconfirm=true to be set so this isn't accidentally executed")
project.task("mlDeployDatabases", type: DeployDatabasesTask, group: dbGroup, dependsOn: "mlPrepareRestApiDependencies", description: "Deploy each database, updating it if it exists, in the configuration directory")
project.task("mlMergeContentDatabase", type: MergeContentDatabaseTask, group: dbGroup, description: "Merge the database named by mlAppConfig.contentDatabaseName")
project.task("mlMergeDatabase", type: MergeDatabaseTask, group: dbGroup, description: "Merge the database named by the project property dbName; e.g. gradle mlMergeDatabase -PdbName=my-database")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.marklogic.gradle.task.databases

import com.marklogic.gradle.task.AbstractConfirmableTask
import com.marklogic.mgmt.resource.databases.DatabaseManager
import org.gradle.api.GradleException

class DeleteDatabaseTask extends AbstractConfirmableTask {

@Override
void executeIfConfirmed() {
if (project.hasProperty("database")) {
String db = project.property("database")
DatabaseManager mgr = new DatabaseManager(getManageClient())
mgr.setForestDelete(DatabaseManager.DELETE_FOREST_DATA)
println "Deleting primary and replica forests for database: " + db
mgr.deleteForestsAndReplicas(db)
println "Deleting database: " + db
mgr.deleteByName(db)
println "Finished deleting database: " + db
} else {
throw new GradleException("The property 'database' must be specified")
}
}
}

0 comments on commit bd7f43c

Please sign in to comment.