Skip to content

Instantly share code, notes, and snippets.

@prestonmcgowan
Last active April 16, 2019 17:56
Show Gist options
  • Save prestonmcgowan/7785ecb121f1e4b667a22cfeb097b551 to your computer and use it in GitHub Desktop.
Save prestonmcgowan/7785ecb121f1e4b667a22cfeb097b551 to your computer and use it in GitHub Desktop.
'use strict';
// Set this to the output of app-server-components.sjs
const itemsToDelete = {"group":{"name":"Default", "id":"9058960804898839955"}, "appServer":{"name":"myApp", "id":"9351623035930725670"}, "contentDatabase":{"name":"myApp-content", "id":"743264865753505898", "forests":[{"name":"myApp-content-1", "id":"5044318450693390831"}, {"name":"myApp-content-2", "id":"12748819722917748087"}, {"name":"myApp-content-3", "id":"7007370367638532332"}]}, "modulesDatabase":{"name":null, "id":null, "forests":null}, "schemasDatabase":{"name":null, "id":null, "forests":null}, "triggersDatabase":{"name":null, "id":null, "forests":null}};
// Keep hitting "run" until you see "All Done"
const admin = require('/MarkLogic/admin.xqy');
let config = admin.getConfiguration();
let message = "Lets get it on";
if (admin.appserverExists(config, itemsToDelete.group.id, itemsToDelete.appServer.name)) { //admin.appserverGetName(config, itemsToDelete.appServer.id)) {
config = admin.appserverDelete(config, itemsToDelete.appServer.id);
admin.saveConfiguration(config);
message = "Deleted the App Server. Restarting.";
} else if (admin.databaseExists(config, itemsToDelete.contentDatabase.name)) {
config = admin.databaseDelete(config, [itemsToDelete.contentDatabase.id, itemsToDelete.modulesDatabase.id, itemsToDelete.triggersDatabase.id]);
admin.saveConfigurationWithoutRestart(config);
message = "Deleted the Content and Modules Databases";
} else if (admin.databaseExists(config, itemsToDelete.schemasDatabase.name)) {
config = admin.databaseDelete(config, [itemsToDelete.schemasDatabase.id]);
admin.saveConfigurationWithoutRestart(config);
message = "Deleted the Schema Database";
} else if (admin.forestExists(config, itemsToDelete.contentDatabase.forests[0].name)) {
let forestIds = itemsToDelete.contentDatabase.forests.map((forest) => forest.id);
forestIds = (itemsToDelete.modulesDatabase.forests) ? forestIds.concat( itemsToDelete.modulesDatabase.forests.map((forest) => forest.id) ) : forestIds;
forestIds = (itemsToDelete.triggersDatabase.forests) ? forestIds.concat( itemsToDelete.triggersDatabase.forests.map((forest) => forest.id) ) : forestIds;
config = admin.forestDelete(config, forestIds, true); // WARNING: Data will be deleted
admin.saveConfigurationWithoutRestart(config);
message = "Deleted the Forests";
} else {
message = "All Done";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment