From d1819c6503ec81d9235e01bb0890e92e6363b227 Mon Sep 17 00:00:00 2001 From: Paul Lockaby <633173+plockaby@users.noreply.github.com> Date: Thu, 18 May 2023 00:31:13 -0700 Subject: [PATCH] Add database options (#406) * adding support for database connection options * a better default --- .env.sample | 2 ++ docs/Options.md | 6 ++++++ siteroot/settings/base.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/.env.sample b/.env.sample index d13947c..00aaf59 100644 --- a/.env.sample +++ b/.env.sample @@ -45,3 +45,5 @@ LD_DB_HOST= # Port use to connect to the database server # Should use the default port if not set LD_DB_PORT= +# Any additional options to pass to the database (default: {}) +LD_DB_OPTIONS= diff --git a/docs/Options.md b/docs/Options.md index 8809e30..a340442 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -150,6 +150,12 @@ Values: `Integer` | Default = None The port of the database server. Should use the default port if left empty, for example `5432` for PostgresSQL. +### `LD_DB_OPTIONS` + +Values: `String` | Default = `{}` + +A json string with additional options for the database. Passed directly to OPTIONS. + ### `LD_FAVICON_PROVIDER` Values: `String` | Default = `https://t1.gstatic.com/faviconV2?url={url}&client=SOCIAL&type=FAVICON` diff --git a/siteroot/settings/base.py b/siteroot/settings/base.py index a838044..1e70dbd 100644 --- a/siteroot/settings/base.py +++ b/siteroot/settings/base.py @@ -10,6 +10,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ """ +import json import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) @@ -204,6 +205,7 @@ LD_DB_DATABASE = os.getenv('LD_DB_DATABASE', 'linkding') LD_DB_USER = os.getenv('LD_DB_USER', 'linkding') LD_DB_PASSWORD = os.getenv('LD_DB_PASSWORD', None) LD_DB_PORT = os.getenv('LD_DB_PORT', None) +LD_DB_OPTIONS = json.loads(os.getenv('LD_DB_OPTIONS') or '{}') if LD_DB_ENGINE == 'postgres': default_database = { @@ -213,11 +215,13 @@ if LD_DB_ENGINE == 'postgres': 'PASSWORD': LD_DB_PASSWORD, 'HOST': LD_DB_HOST, 'PORT': LD_DB_PORT, + 'OPTIONS': LD_DB_OPTIONS, } else: default_database = { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'data', 'db.sqlite3'), + 'OPTIONS': LD_DB_OPTIONS, } DATABASES = {