-
Notifications
You must be signed in to change notification settings - Fork 6
GPII-3138: Update Prefs Safes and their GPII Keys in the data base #6
base: master
Are you sure you want to change the base?
Changes from 10 commits
edfc334
760b795
3583141
f2374d4
c1a494f
a8a161f
98e70d3
d042026
96bddc6
7a290b2
01908db
372e9c4
8118574
d42e2a5
a730327
0e9577b
933d03f
0ba06e4
9bb3f46
8c60cd8
ab35aa1
0034b4d
2059195
29b414e
c9cf927
82aa358
c14879c
b7bea34
9b4b3f1
0ec50b3
05e8dcc
a147932
ab4d265
2680cd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| STATIC_DATA_DIR=${STATIC_DATA_DIR:-/home/node/universal/testData/dbData} | ||
| BUILD_DATA_DIR=${BUILD_DATA_DIR:-/home/node/universal/build/dbData} | ||
| NODE_PATH=${NODE_PATH:-/home/node/universal} | ||
|
|
||
| log() { | ||
| echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | ||
|
|
@@ -31,7 +32,24 @@ if [ -z "$COUCHDB_URL" ]; then | |
| fi | ||
|
|
||
| log "Starting" | ||
| log "Clear index: $CLEAR_INDEX" | ||
| log "Static: $STATIC_DATA_DIR" | ||
| log "Build: $BUILD_DATA_DIR" | ||
| log "Node path: $NODE_PATH" | ||
| log "Working directory: `pwd`" | ||
|
|
||
| # Set up universal | ||
| git clone https://github.com/GPII/universal.git | ||
|
||
| cd universal | ||
| rm -f package-lock.json | ||
|
||
| npm install json5 | ||
| npm install fs | ||
| npm install rimraf | ||
| npm install mkdirp | ||
| node scripts/convertPrefs.js testData/preferences/ build/dbData/ | ||
| cd - | ||
|
|
||
| # Initialize (possibly clear) data base | ||
| if [ ! -z "$CLEAR_INDEX" ]; then | ||
| log "Deleting database at $COUCHDB_URL" | ||
|
||
| if ! curl -fsS -X DELETE "$COUCHDB_URL"; then | ||
|
|
@@ -45,5 +63,6 @@ if ! curl -fsS -X PUT "$COUCHDB_URL"; then | |
| fi | ||
|
|
||
| # Submit data | ||
| node $NODE_PATH/scripts/deleteSnapsets.js $COUCHDB_URL | ||
| loadData $STATIC_DATA_DIR | ||
| loadData $BUILD_DATA_DIR | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| var http = require('http'); | ||
| var querystring = require("querystring"); | ||
|
|
||
| var baseOptions = { | ||
| hostname: "localhost", | ||
| port: 5984, | ||
| method: "GET" | ||
| }; | ||
|
|
||
| // var snapSetViewOptions = baseOptions; snapSetViewOptions.path = /gpii/_design/views/_view/findSnapsetPrefsSafes" | ||
|
|
||
| var snapSetsViewOptions = { | ||
| hostname: "localhost", | ||
| port: 5984, | ||
| path: "/gpii/_design/views/_view/findSnapsetPrefsSafes", | ||
| method: "GET" | ||
| }; | ||
|
|
||
| var globalToRemoveArray = []; | ||
|
|
||
| var snapSetsString=""; | ||
| var snapSetReq = http.request(snapSetsViewOptions, function (response) { | ||
| response.setEncoding("utf8"); | ||
|
|
||
| response.on("data", function (chunk) { | ||
| snapSetsString += chunk; | ||
| }); | ||
|
|
||
| response.on("end", function () { | ||
| // console.log(snapSetsString); | ||
| var snapSets = JSON.parse(snapSetsString); | ||
| // debugger; | ||
| for (var i=0; i < snapSets.rows.length; i++) { | ||
| var aSnapSet = snapSets.rows[i]; | ||
| // console.log("[" + aSnapSet.id + "," + aSnapSet.value._rev + "]"); | ||
| } | ||
| globalToRemoveArray.push(snapSets.rows[0].value); | ||
| globalToRemoveArray.push(snapSets.rows[5].value); | ||
| globalToRemoveArray[0]._deleted = true; | ||
| // globalToRemoveArray[1]._deletion = true; | ||
| console.log(JSON.stringify(globalToRemoveArray[0], null, 2)); | ||
| addGpiiKeysToRemove(globalToRemoveArray); | ||
| console.log("FOO!"); | ||
| }); | ||
| }); | ||
| snapSetReq.end(); | ||
|
|
||
| getOmarOptions = { | ||
| hostname: "localhost", | ||
| port: 5984, | ||
| path: "/gpii/omar", | ||
| method: "GET" | ||
| }; | ||
|
|
||
| var deleteString = ""; | ||
| var deleteRequest = http.request(getOmarOptions, function (response) { | ||
| console.log("STATUS: " + response.statusCode); | ||
| response.setEncoding("utf8"); | ||
|
|
||
| response.on("data", function (chunk) { | ||
| deleteString += chunk; | ||
| }); | ||
|
|
||
| response.on("end", function () { | ||
| console.log(deleteString); | ||
| }); | ||
| }); | ||
| deleteRequest.end(); | ||
|
|
||
|
|
||
| getGpiiKeysOptions = { | ||
| hostname: "localhost", | ||
| port: 5984, | ||
| path: "/gpii/_design/views/_view/findGpiiKeysByPrefsSafeId", | ||
| method: "GET" | ||
|
|
||
| }; | ||
| function addGpiiKeysToRemove (anArray) { | ||
| var gpiiKeyId = anArray[0]._id; | ||
| console.log("addGpiiKeysToRemove: _id is " + gpiiKeyId); | ||
| getGpiiKeysOptions.path += ("?key=%22" + gpiiKeyId + "%22"); | ||
| console.log("addGpiiKeysToRemove: query is " + getGpiiKeysOptions.path); | ||
| var getGpiiKeyReq = http.request(getGpiiKeysOptions, function (resp) { | ||
| var respString = ""; | ||
| resp.setEncoding("utf8"); | ||
| resp.on("data", function (chunk) { | ||
| respString += chunk; | ||
| }); | ||
| resp.on("end", function () { | ||
| var gpiiKeyRecords = JSON.parse(respString); | ||
| gpiiKeyRecords.rows.forEach(function (record) { | ||
| record.value._deleted = true; | ||
| anArray.push(record.value); | ||
| }); | ||
| console.log("addGpiiKeysToRemove onEnd: " + JSON.stringify (anArray, null, 2)); | ||
| doBatchDelete(anArray); | ||
| }); | ||
| }); | ||
| getGpiiKeyReq.end(); | ||
| } | ||
|
|
||
| batchDeleteOptions = { | ||
| hostname: "localhost", | ||
| port: 5984, | ||
| path: "/gpii/_bulk_docs", | ||
| method: "POST", | ||
| // method: "DELETE", | ||
| headers: { | ||
| "Accept": "application/json", | ||
| "Content-Length": 0, // fill in later | ||
| "Content-Type": "application/json" | ||
| } | ||
| }; | ||
| var batchPostData = ""; | ||
| function doBatchDelete (anArray) { | ||
| var theDocs = {}; | ||
| theDocs["docs"] = anArray; | ||
| batchPostData = JSON.stringify(theDocs); | ||
| batchDeleteOptions.headers["Content-Length"] = Buffer.byteLength(batchPostData); | ||
| console.log("doBatchDelete: " + batchPostData); | ||
| console.log("doBatchDelete: " + JSON.stringify(batchDeleteOptions, null, 2)); | ||
| var batchDeleteReq = http.request(batchDeleteOptions, function (res) { | ||
| console.log("STATUS: " + res.statusCode); | ||
| console.log("HEADERS: " + JSON.stringify(res.headers, null, 2)); | ||
| res.setEncoding('utf8'); | ||
| res.on('data', (chunk) => { | ||
| console.log("BODY: " + chunk); | ||
| }); | ||
| res.on('end', function () { | ||
| console.log('No more data in response.'); | ||
| }); | ||
| }); | ||
| batchDeleteReq.on('error', function (e) { | ||
| console.error("problem with batchDeleteReq: " + e.message); | ||
| }); | ||
| batchDeleteReq.write(batchPostData); | ||
| batchDeleteReq.end(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking if a var name like
UNIVERSAL_PATHis better thanNODE_PATHbecause this path is defined for accessing scripts/ in the universal repo. What do you think?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that
NODE_PATHisn't very clear.It's a little ambiguous because "universal" can mean so many things, but I like
UNIVERSAL_DIRor maybeUNIVERSAL_ROOT_DIR(_PATHisn't consistent with how the other variables are named).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a way to eliminate the
NODE_PATHvariable entirely. Related: I discovered that since thedeleteSnapSets.jsscript uses infusion, annpm install infusionis required here. Simply cloning universal does not provide an instance of infusion within itsnode_modulesfolder. If infusion is so installed, and acd universalis executed after it is cloned (already done), that's enough for thenodecommand to find infusion. No need forNODE_PATH.