Skip to content

Commit

Permalink
fix: how we parse the DBs to be synced and suggest comma separated li…
Browse files Browse the repository at this point in the history
…st instead of a space separated one
  • Loading branch information
njuguna-n authored Oct 31, 2024
1 parent 43997a8 commit af0b1e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion couch2pg/src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions couch2pg/tests/unit/db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
2 changes: 1 addition & 1 deletion env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af0b1e8

Please sign in to comment.