diff --git a/src/Connection/Manager.ts b/src/Connection/Manager.ts index d7f51c32..1de0a97e 100644 --- a/src/Connection/Manager.ts +++ b/src/Connection/Manager.ts @@ -86,20 +86,11 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager */ public add (connectionName: string, config: ConnectionConfigContract): void { /** - * Raise an exception when someone is trying to re-add the same connection. We - * should not silently avoid this scanerio, since there is a valid use case - * in which the config has been changed and someone wants to re-add the - * connection with new config. In that case, they must - * - * 1. Close and release the old connection - * 2. Then add the new connection + * Noop when connection already exists. If one wants to change the config, they + * must release the old connection and add a new one */ - if (this.isConnected(connectionName)) { - throw new Exception( - `Attempt to add duplicate connection ${connectionName} failed`, - 500, - 'E_DUPLICATE_DB_CONNECTION', - ) + if (this.has(connectionName)) { + return } this._logger.trace({ connection: connectionName }, 'adding new connection to the manager') diff --git a/test/connection/connection-manager.spec.ts b/test/connection/connection-manager.spec.ts index b4f5a965..e0de9174 100644 --- a/test/connection/connection-manager.spec.ts +++ b/test/connection/connection-manager.spec.ts @@ -51,13 +51,13 @@ test.group('ConnectionManager', (group) => { assert.isFalse(manager.isConnected('primary')) }) - test('raise exception when attempt to add a duplication connection', async (assert) => { + test('add duplicate connection must be a noop', async (assert) => { const manager = new ConnectionManager(getLogger()) manager.add('primary', getConfig()) manager.connect('primary') - const fn = () => manager.add('primary', getConfig()) - assert.throw(fn, 'E_DUPLICATE_DB_CONNECTION: Attempt to add duplicate connection primary failed') + manager.add('primary', Object.assign({}, getConfig(), { client: 'foo' })) + assert.notEqual(manager.get('primary')!.config.client, 'foo') }) test('patch config when connection is not in open state', async (assert) => {