From ed9c7354d79ec3cbb727273cab56cd973bda0e5f Mon Sep 17 00:00:00 2001 From: Phil Bolduc Date: Thu, 12 Oct 2023 10:11:37 -0700 Subject: [PATCH] Add ability to set database connection string --- app/README.md | 1 + app/config/custom-environment-variables.json | 1 + app/knexfile.js | 3 +++ 3 files changed, 5 insertions(+) diff --git a/app/README.md b/app/README.md index 906d1e16..13fd9297 100644 --- a/app/README.md +++ b/app/README.md @@ -54,6 +54,7 @@ The following variables configure the use of a backend database to support user- | Config Var | Env Var | Default | Notes | | --- | --- | --- | --- | +| `connectionString` | `DB_CONNECTION_STRING` | coms | COMS database connection string, This setting has the highest priority to use. If not specified then connection details will be determined using the individual connection fields | | `database` | `DB_DATABASE` | coms | COMS database name | | `host` | `DB_HOST` | localhost | Database conection hostname | | `username` | `DB_USERNAME` | app | Database account username | diff --git a/app/config/custom-environment-variables.json b/app/config/custom-environment-variables.json index 961352fc..12b72d38 100644 --- a/app/config/custom-environment-variables.json +++ b/app/config/custom-environment-variables.json @@ -5,6 +5,7 @@ "username": "BASICAUTH_USERNAME" }, "db": { + "connectionString": "DB_CONNECTION_STRING", "database": "DB_DATABASE", "host": "DB_HOST", "password": "DB_PASSWORD", diff --git a/app/knexfile.js b/app/knexfile.js index 221267c3..0562151b 100644 --- a/app/knexfile.js +++ b/app/knexfile.js @@ -33,6 +33,9 @@ const logWrapper = (level, msg) => log.log(level, msg); module.exports = { client: 'pg', connection: { + // connectionString is highest priority to use. If left unspecified then connection + // details will be determined using the individual connection fields (host, port, etc) + connectionString: config.has('db.connectionString') ? config.get('db.connectionString') : undefined, host: config.get('db.host'), user: config.get('db.username'), password: config.get('db.password'),