From af0b1e8923eeab1212752b821cfa71f89b7586b6 Mon Sep 17 00:00:00 2001 From: njuguna-n <141340177+njuguna-n@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:53:47 +0300 Subject: [PATCH] fix: how we parse the DBs to be synced and suggest comma separated list instead of a space separated one --- couch2pg/src/db.js | 2 +- couch2pg/tests/unit/db.spec.js | 10 ++++++++++ env.template | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/couch2pg/src/db.js b/couch2pg/src/db.js index e7b51c7..3c4e88a 100644 --- a/couch2pg/src/db.js +++ b/couch2pg/src/db.js @@ -42,4 +42,4 @@ export const getCouchDbClient = (dbName) => { const url = `${COUCHDB_SECURE === 'true' ? 'https' : 'http'}://${COUCHDB_USER}:${COUCHDB_PASSWORD}@${COUCHDB_HOST}:${COUCHDB_PORT}/${dbName}`; return new PouchDb(url, { skip_setup: true }); }; -export const couchDbs = COUCHDB_DBS.split(',').map(db => db.trim()); +export const couchDbs = COUCHDB_DBS.split(/[ ,]+/).map(db => db.trim()); // split by comma or space diff --git a/couch2pg/tests/unit/db.spec.js b/couch2pg/tests/unit/db.spec.js index f91ee31..4d3db3d 100644 --- a/couch2pg/tests/unit/db.spec.js +++ b/couch2pg/tests/unit/db.spec.js @@ -111,4 +111,14 @@ describe('db', () => { ]); }); }); + + describe('handle multiple DBs', () => { + it('should split by space or comma', async () => { + process.env.COUCHDB_DBS = 'db1, db2 db3,db4'; + + db = await esmock('../../src/db', { pg, 'pouchdb-core': pouchDb }); + const expectedDbs = ['db1', 'db2', 'db3', 'db4']; + expect(db.couchDbs).to.deep.equal(expectedDbs); + }); + }); }); diff --git a/env.template b/env.template index 7c54635..eb25151 100644 --- a/env.template +++ b/env.template @@ -14,7 +14,7 @@ DATAEMON_INTERVAL=5 # couchdb COUCHDB_USER=medic COUCHDB_PASSWORD=password -COUCHDB_DBS="medic" # space separated list of databases you want to sync e.g "medic medic_sentinel" +COUCHDB_DBS="medic" # comma separated list of databases you want to sync e.g "medic, medic_sentinel" COUCHDB_HOST=couchdb COUCHDB_PORT=5984 COUCHDB_SECURE=false