Skip to content

Commit

Permalink
[csv-to-docs] Don't generate doc IDs based on URL
Browse files Browse the repository at this point in the history
This should mean that converting identical CSV for two different servers (e.g.
test servers) should create docs with the same _id fields.
  • Loading branch information
alxndrsn committed Oct 18, 2017
1 parent 7fe67cc commit f685e58
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 19 deletions.
6 changes: 2 additions & 4 deletions src/fn/csv-to-docs.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
const csvParse = require('csv-parse/lib/sync');
const fs = require('../lib/sync-fs');
const info = require('../lib/log').info;
const skipFn = require('../lib/skip-fn');
const stringify = require('canonical-json/index2');
const trace = require('../lib/log').trace;
const uuid5 = require('uuid/v5');
const warn = require('../lib/log').warn;

require('../lib/polyfill');

module.exports = (projectDir, couchUrl) => {
if(!couchUrl) return skipFn('no couch URL set');
const couchUrlUuid = uuid5(couchUrl, uuid5.URL);
module.exports = projectDir => {
const couchUrlUuid = uuid5('http://medicmobile.org/configurer/csv-to-docs/permanent-hash', uuid5.URL);

const csvDir = `${projectDir}/csv`;
if(!fs.exists(csvDir)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"form": "follow_up",
"type": "report",
"chw_id": "df59cf15-043f-5df5-adb0-1b03c6f4c0eb",
"chw_id": "aa2c123f-7824-585c-8880-5f9c09b81e34",
"name": "Charlie Chalk",
"field": {
"z_score": 52,
"happy": true,
"notes": "A boisterous fellow",
"fam": "b8f94f58-5258-5ada-9025-1226ef04bb6e"
"fam": "cc56b63e-aade-5e30-9f06-c4dcd31587ff"
},
"_id": "08603f1d-9044-5ea3-aa20-b14ad294c819"
"_id": "09e3215e-25fc-5960-9034-784d920db457"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"type": "household",
"parent": "abc-123",
"family_name": "Burns",
"_id": "ce75e6e7-a634-5f5d-bcbe-0f3b5fec0c6d"
"_id": "40f8bfc0-0757-5a7f-ba60-5abe0665b3c8"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"type": "person",
"parent": "b8f94f58-5258-5ada-9025-1226ef04bb6e",
"parent": "40f8bfc0-0757-5a7f-ba60-5abe0665b3c8",
"family_name": "Atkins",
"name": "Anna",
"date_of_birth": "1987-12-03T00:00:00.000Z",
"phone": "+447890000001",
"child_count": 1,
"_id": "df59cf15-043f-5df5-adb0-1b03c6f4c0eb"
"_id": "53332749-f55d-5ffd-82bb-62bac3758c84"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"form": "follow_up",
"type": "report",
"chw_id": "4a4664fe-4db1-59de-a596-952d04a321c2",
"chw_id": "53332749-f55d-5ffd-82bb-62bac3758c84",
"name": "Donnie Darko",
"field": {
"z_score": 64,
"happy": false,
"notes": "A troubled youth",
"fam": "ce75e6e7-a634-5f5d-bcbe-0f3b5fec0c6d"
"fam": "40f8bfc0-0757-5a7f-ba60-5abe0665b3c8"
},
"_id": "5c7e4e27-302f-5de0-a0b6-45a4c31c00f4"
"_id": "70e235bc-b23a-5b9a-addb-60e9d487e7e3"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"type": "person",
"parent": "ce75e6e7-a634-5f5d-bcbe-0f3b5fec0c6d",
"parent": "cc56b63e-aade-5e30-9f06-c4dcd31587ff",
"family_name": "Atkins",
"name": "Anna",
"date_of_birth": "1987-12-03T00:00:00.000Z",
"phone": "+447890000001",
"child_count": 1,
"_id": "4a4664fe-4db1-59de-a596-952d04a321c2"
"_id": "aa2c123f-7824-585c-8880-5f9c09b81e34"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"type": "person",
"parent": "ce75e6e7-a634-5f5d-bcbe-0f3b5fec0c6d",
"parent": "40f8bfc0-0757-5a7f-ba60-5abe0665b3c8",
"family_name": "Burns",
"name": "Beatrice",
"date_of_birth": "1979-01-31T00:00:00.000Z",
"phone": "+447890000002",
"child_count": 2,
"_id": "7cdf3dac-9ca2-5cac-9eb7-bb1238d9247d"
"_id": "aa616a09-4c8c-5405-a472-76528f5d682a"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"type": "household",
"parent": "abc-123",
"family_name": "Atkins",
"_id": "b8f94f58-5258-5ada-9025-1226ef04bb6e"
"_id": "cc56b63e-aade-5e30-9f06-c4dcd31587ff"
}
2 changes: 1 addition & 1 deletion test/fn/csv-to-docs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('csv-to-docs', function() {
if(err) done(err);

// when
csvToDocs(testDir, 'http://admin:pass@localhost:5988/medic')
csvToDocs(testDir)
.then(() => {
const generatedDocsDir = `${testDir}/json_docs`;
const expectedDocsDir = `${testDir}/expected-json_docs`;
Expand Down

0 comments on commit f685e58

Please sign in to comment.