From 144e832cdc60dbce0f642d05637ce254d322438c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20=C3=85hsberg?= Date: Fri, 20 Nov 2020 11:37:56 +0100 Subject: [PATCH] feat: Add support for explicitly set database version. (#654) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mathias Ã…hsberg --- docs/getting-started.md | 3 ++- lib/db/db-pool.js | 1 + lib/options.js | 1 + lib/options.test.js | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 45c8ea9279..234ab5bd3c 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -47,9 +47,10 @@ Available unleash options include: - _user_ - the database username (`DATABASE_USERNAME`) - _password_ - the database password (`DATABASE_PASSWORD`) - _host_ - the database hostname (`DATABASE_HOST`) - - _port_ - the datbase port defaults to 5432 (`DATABASE_PORT`) + - _port_ - the database port defaults to 5432 (`DATABASE_PORT`) - _database_ - the database name to be used (`DATABASE_NAME`) - _ssl_ - an object describing ssl options, see https://node-postgres.com/features/ssl (`DATABASE_SSL`, as a stringified json object) + - _version_ - the postgres database version. Used to connect a non-standard database. Defaults to `undefined`, which let the underlying adapter to detect the version automatically. (`DATABASE_VERSION`) - **databaseUrl** - the postgres database url to connect to. Only used if _db_ object is not specified. Should include username/password. This value may also be set via the `DATABASE_URL` environment variable. Alternatively, if you would like to read the database url from a file, you may set the `DATABASE_URL_FILE` environment variable with the full file path. The contents of the file must be the database url exactly. - **databaseSchema** - the postgres database schema to use. Defaults to 'public'. - **port** - which port the unleash-server should bind to. If port is omitted or is 0, the operating system will assign an arbitrary unused port. Will be ignored if pipe is specified. This value may also be set via the `HTTP_PORT` environment variable diff --git a/lib/db/db-pool.js b/lib/db/db-pool.js index 3b73b1d7ea..8fd7b39031 100644 --- a/lib/db/db-pool.js +++ b/lib/db/db-pool.js @@ -12,6 +12,7 @@ module.exports.createDb = function({ const logger = getLogger('db-pool.js'); return knex({ client: 'pg', + version: db.version, connection: db, pool: { min: poolMin, max: poolMax }, searchPath: databaseSchema, diff --git a/lib/options.js b/lib/options.js index f0b35de73c..3b844bc9a6 100644 --- a/lib/options.js +++ b/lib/options.js @@ -34,6 +34,7 @@ function defaultOptions() { ? JSON.parse(process.env.DATABASE_SSL) : false, driver: 'postgres', + version: process.env.DATABASE_VERSION, }, port: process.env.HTTP_PORT || process.env.PORT || 4242, host: process.env.HTTP_HOST, diff --git a/lib/options.test.js b/lib/options.test.js index 846b01560c..d724f8a8c6 100644 --- a/lib/options.test.js +++ b/lib/options.test.js @@ -135,6 +135,7 @@ test('should prefer custom db connection options', t => { database: 'db_database', ssl: false, driver: 'postgres', + version: '10', }; const options = createOptions({ databaseUrl, db });