Skip to content

Commit 8c181b4

Browse files
committed
#126 Reloading schemas now involves deleting "user" schemas instead of clearing the schemas database
1 parent 5e38d6c commit 8c181b4

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ class MarkLogicPlugin implements Plugin<Project> {
129129
project.task("mlClearContentDatabase", type: ClearContentDatabaseTask, group: dbGroup, description: "Deletes all documents in the content database; requires -Pconfirm=true to be set so this isn't accidentally executed")
130130
project.task("mlClearDatabase", type: ClearDatabaseTask, group: dbGroup, description: "Deletes all documents in a database specified by -Pdatabase=(name); requires -Pconfirm=true to be set so this isn't accidentally executed")
131131
project.task("mlClearModulesDatabase", type: ClearModulesDatabaseTask, group: dbGroup, dependsOn: "mlDeleteModuleTimestampsFile", description: "Deletes potentially all of the documents in the modules database; has a property for excluding documents from deletion")
132-
project.task("mlClearSchemasDatabase", type: ClearSchemasDatabaseTask, group: dbGroup, description: "Deletes all documents in the schemas database")
132+
project.task("mlClearSchemasDatabase", type: ClearSchemasDatabaseTask, group: dbGroup, description: "Deletes all documents in the schemas database. " +
133+
"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.")
133134
project.task("mlClearTriggersDatabase", type: ClearTriggersDatabaseTask, group: dbGroup, description: "Deletes all documents in the triggers database")
134135
project.task("mlDeployDatabases", type: DeployDatabasesTask, group: dbGroup, dependsOn: "mlPrepareRestApiDependencies", description: "Deploy each database, updating it if it exists, in the configuration directory")
135136
project.task("mlMergeContentDatabase", type: MergeContentDatabaseTask, group: dbGroup, description: "Merge the database named by mlAppConfig.contentDatabaseName")
@@ -220,8 +221,9 @@ class MarkLogicPlugin implements Plugin<Project> {
220221
project.task("mlDeployRestApis", type: DeployRestApisTask, group: restApisGroup, description: "Deploy the REST API instances defined by a resource file or the mlRestPort/mlTestRestPort properties")
221222

222223
String schemasGroup = "ml-gradle Schemas"
223-
project.task("mlLoadSchemas", type: LoadSchemasTask, group: schemasGroup, description: "Loads special-purpose data into the schemas database (XSD schemas, Inference rules, and [MarkLogic 9] Extraction Templates)").mustRunAfter("mlClearSchemasDatabase")
224-
project.task("mlReloadSchemas", dependsOn: ["mlClearSchemasDatabase", "mlLoadSchemas"], group: schemasGroup, description: "Clears schemas database then loads special-purpose data into the schemas database (XSD schemas, Inference rules, and [MarkLogic 9] Extraction Templates)")
224+
project.task("mlDeleteUserSchemas", type: DeleteUserSchemasTask, group: schemasGroup, description: "Delete documents in a schemas database that were not created via the deployment of resources such as temporal collections or view schemas")
225+
project.task("mlLoadSchemas", type: LoadSchemasTask, group: schemasGroup, description: "Loads special-purpose data into the schemas database (XSD schemas, Inference rules, and [MarkLogic 9] Extraction Templates)").mustRunAfter("mlDeleteUserSchemas")
226+
project.task("mlReloadSchemas", dependsOn: ["mlDeleteUserSchemas", "mlLoadSchemas"], group: schemasGroup, description: "Deletes user schemas via mlDeleteUserSchemas and then loads schemas via mlLoadSchemas")
225227

226228
String serverGroup = "ml-gradle Server"
227229
project.task("mlDeployServers", type: DeployServersTask, group: serverGroup, dependsOn: "mlPrepareRestApiDependencies", description: "Updates the REST API server (if it exists) and deploys each other server, updating it if it exists, in the configuration directory ")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.marklogic.gradle.task.databases
2+
3+
import com.marklogic.gradle.task.MarkLogicTask
4+
import org.gradle.api.tasks.TaskAction
5+
6+
/**
7+
* "User schemas" is intended to be any documents in a schemas database that are loaded by a user as opposed to those
8+
* created via the deployment of resources such as temporal collections and view schemas.
9+
*/
10+
class DeleteUserSchemasTask extends MarkLogicTask {
11+
12+
String xquery
13+
String database
14+
15+
@TaskAction
16+
void deleteUserSchemas() {
17+
if (xquery == null) {
18+
xquery = "cts:not-query(" +
19+
"cts:collection-query((" +
20+
"'http://marklogic.com/xdmp/temporal/axis', " +
21+
"'http://marklogic.com/xdmp/temporal/collection', 'http://marklogic.com/xdmp/view'" +
22+
"))" +
23+
")"
24+
}
25+
26+
if (database == null) {
27+
database = getAppConfig().getSchemasDatabaseName()
28+
}
29+
30+
31+
String fullQuery = "cts:uris((), (), " + xquery + ") ! xdmp:document-delete(.)"
32+
println "Deleting user schemas in database '" + database + "' via : " + fullQuery
33+
34+
def client = newClient()
35+
try {
36+
client.newServerEval().xquery(fullQuery).eval()
37+
} finally {
38+
client.release()
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)