Skip to content

Commit bd7f43c

Browse files
committed
#423 Can now delete a database via mlDeleteDatabase
1 parent 3404a77 commit bd7f43c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class MarkLogicPlugin implements Plugin<Project> {
135135
project.task("mlClearSchemasDatabase", type: ClearSchemasDatabaseTask, group: dbGroup, description: "Deletes all documents in the schemas database. " +
136136
"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.")
137137
project.task("mlClearTriggersDatabase", type: ClearTriggersDatabaseTask, group: dbGroup, description: "Deletes all documents in the triggers database")
138+
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")
138139
project.task("mlDeployDatabases", type: DeployDatabasesTask, group: dbGroup, dependsOn: "mlPrepareRestApiDependencies", description: "Deploy each database, updating it if it exists, in the configuration directory")
139140
project.task("mlMergeContentDatabase", type: MergeContentDatabaseTask, group: dbGroup, description: "Merge the database named by mlAppConfig.contentDatabaseName")
140141
project.task("mlMergeDatabase", type: MergeDatabaseTask, group: dbGroup, description: "Merge the database named by the project property dbName; e.g. gradle mlMergeDatabase -PdbName=my-database")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.marklogic.gradle.task.databases
2+
3+
import com.marklogic.gradle.task.AbstractConfirmableTask
4+
import com.marklogic.mgmt.resource.databases.DatabaseManager
5+
import org.gradle.api.GradleException
6+
7+
class DeleteDatabaseTask extends AbstractConfirmableTask {
8+
9+
@Override
10+
void executeIfConfirmed() {
11+
if (project.hasProperty("database")) {
12+
String db = project.property("database")
13+
DatabaseManager mgr = new DatabaseManager(getManageClient())
14+
mgr.setForestDelete(DatabaseManager.DELETE_FOREST_DATA)
15+
println "Deleting primary and replica forests for database: " + db
16+
mgr.deleteForestsAndReplicas(db)
17+
println "Deleting database: " + db
18+
mgr.deleteByName(db)
19+
println "Finished deleting database: " + db
20+
} else {
21+
throw new GradleException("The property 'database' must be specified")
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)