From 2a1da336306af4b867bbefc87d1ea77e8007db40 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 9 Oct 2018 13:01:12 -0400 Subject: [PATCH 1/5] Fix configuration parentCode --- update-logs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-logs.js b/update-logs.js index 4c5473c..3395fdf 100644 --- a/update-logs.js +++ b/update-logs.js @@ -28,7 +28,7 @@ const updateDocs = (docs, db, callback) => { }; const addParentToConfiguration = (configurations) => { - updateDocs(configurations.map(config => config.parentCode = parentCode), () => { + updateDocs(configurations.map(config => ({ ...config, parentCode})), () => { console.log('Configurations updated'); }); } From 27fb74a50834087b1bde5eed2beba9585f2b471a Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 9 Oct 2018 13:22:19 -0400 Subject: [PATCH 2/5] Fix updating configurations --- update-logs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-logs.js b/update-logs.js index 3395fdf..f11afd6 100644 --- a/update-logs.js +++ b/update-logs.js @@ -28,7 +28,7 @@ const updateDocs = (docs, db, callback) => { }; const addParentToConfiguration = (configurations) => { - updateDocs(configurations.map(config => ({ ...config, parentCode})), () => { + updateDocs(configurations.map(config => ({ ...config, parentCode})), 'configurations', () => { console.log('Configurations updated'); }); } From 914f21d6c8052b40bf4f159d61c56a9cde236241 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 9 Oct 2018 13:52:48 -0400 Subject: [PATCH 3/5] Add replicator for configuration document --- package.json | 1 + update-logs.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/package.json b/package.json index 11cb1cc..91bdc5c 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "homepage": "https://github.com/ole-vi/planet-scripts#readme", "dependencies": { + "btoa": "^1.2.1", "request": "^2.88.0" } } diff --git a/update-logs.js b/update-logs.js index f11afd6..f88e364 100644 --- a/update-logs.js +++ b/update-logs.js @@ -1,5 +1,6 @@ #!/usr/bin/env node const request = require('request'); +const btoa = require('btoa'); const user = process.argv[2]; const pass = process.argv[3]; @@ -29,10 +30,33 @@ const updateDocs = (docs, db, callback) => { const addParentToConfiguration = (configurations) => { updateDocs(configurations.map(config => ({ ...config, parentCode})), 'configurations', () => { + createConfigurationReplication(configurations[0]); console.log('Configurations updated'); }); } +const createConfigurationReplication = (configuration) => { + const replicationObject = { + // Name the id always after the local database + '_id': 'configuration_push', + 'source': { + 'url': couchAddress + 'configurations' + }, + 'target': { + 'headers': { + 'Authorization': 'Basic ' + btoa(configuration.adminName + ':' + pass) + }, + 'url': 'https://' + configuration.parentDomain + '/communityregistrationrequests' + }, + 'create_target': false, + 'owner': user, + 'continuous': false + }; + request.post({ uri: couchAddress + '_replicator', body: replicationObject, json: true }, () => { + console.log('Configuration replicating to parent'); + }); +} + const appendPlanetCodes = (array, codeField) => { return array.map(item => ({ ...item, parentCode, [codeField]: code })); }; From 40a5cff6166762e00c07386cc2af775d60d17ba3 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 9 Oct 2018 13:58:43 -0400 Subject: [PATCH 4/5] Fix replication source address --- update-logs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update-logs.js b/update-logs.js index f88e364..1dff578 100644 --- a/update-logs.js +++ b/update-logs.js @@ -36,11 +36,12 @@ const addParentToConfiguration = (configurations) => { } const createConfigurationReplication = (configuration) => { + const replicationAddress = protocol + '://' + user + ':' + pass + '@localhost:5984/'; const replicationObject = { // Name the id always after the local database '_id': 'configuration_push', 'source': { - 'url': couchAddress + 'configurations' + 'url': replicationAddress + 'configurations' }, 'target': { 'headers': { From 26a82db0c5e4c5a1f8c7457e75bfe33f9c8c2f72 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 9 Oct 2018 14:10:23 -0400 Subject: [PATCH 5/5] Add timestamp to replication id --- update-logs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-logs.js b/update-logs.js index 1dff578..3ec6178 100644 --- a/update-logs.js +++ b/update-logs.js @@ -39,7 +39,7 @@ const createConfigurationReplication = (configuration) => { const replicationAddress = protocol + '://' + user + ':' + pass + '@localhost:5984/'; const replicationObject = { // Name the id always after the local database - '_id': 'configuration_push', + '_id': 'configuration_push_' + Date.now(), 'source': { 'url': replicationAddress + 'configurations' },