Last active
April 9, 2019 10:57
-
-
Save prestonmcgowan/9a63376b9bd922d06db34e7747e3d20b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const APP_SERVER_TO_DELETE = 'myApp'; | |
const admin = require('/MarkLogic/admin.xqy'); | |
let config = admin.getConfiguration(); | |
const groupId = fn.head(admin.getGroupIds(config)); // ASSUMPTION: only one group | |
const appServerId = admin.appserverGetId(config, groupId, APP_SERVER_TO_DELETE); | |
const databaseId = admin.appserverGetDatabase(config, appServerId); | |
const modulesId = admin.appserverGetModulesDatabase(config, appServerId); // returns 0 if the modules is set to filesystem | |
const schemasId = admin.databaseGetSchemaDatabase(config, databaseId); // returns 0 if the schema is (none) | |
const triggersId = admin.databaseGetTriggersDatabase(config, databaseId); // returns 0 if the triggers is (none) | |
const databaseForests = admin.databaseGetAttachedForests(config, databaseId).toArray(); | |
const modulesForests = (modulesId === 0) ? null : admin.databaseGetAttachedForests(config, modulesId).toArray(); | |
const schemasForests = (schemasId === 0) ? null : admin.databaseGetAttachedForests(config, schemasId).toArray(); | |
const triggersForests = (triggersId === 0) ? null : admin.databaseGetAttachedForests(config, triggersId).toArray(); | |
const itemsToDelete = { | |
group: { | |
name: xdmp.groupName(groupId), | |
id: groupId | |
}, | |
appServer : { | |
name: APP_SERVER_TO_DELETE, | |
id: appServerId | |
}, | |
contentDatabase: { | |
name: xdmp.databaseName(databaseId), | |
id: databaseId, | |
forests: databaseForests.map( (id) => { return { name: xdmp.forestName(id), id: id}}) | |
}, | |
modulesDatabase: { | |
name: (modulesId === 0) ? null : xdmp.databaseName(modulesId), | |
id: (modulesId === 0) ? null : modulesId, | |
forests: (modulesId === 0) ? null : modulesForests.map( (id) => { return { name: xdmp.forestName(id), id: id}}) | |
}, | |
schemasDatabase: { | |
name: (schemasId === 0) ? null : xdmp.databaseName(schemasId), | |
id: (schemasId === 0) ? null : schemasId, | |
forests: (schemasId === 0) ? null : schemasForests.map( (id) => { return { name: xdmp.forestName(id), id: id}}) | |
}, | |
triggersDatabase: { | |
name: (triggersId === 0) ? null : xdmp.databaseName(triggersId), | |
id: (triggersId === 0) ? null : triggersId, | |
forests: (triggersId === 0) ? null : triggersForests.map( (id) => { return { name: xdmp.forestName(id), id: id}}) | |
} | |
}; | |
itemsToDelete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment