Add database options (#406)

* adding support for database connection options

* a better default
This commit is contained in:
Paul Lockaby 2023-05-18 00:31:13 -07:00 committed by GitHub
parent 353ba433f0
commit d1819c6503
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View file

@ -45,3 +45,5 @@ LD_DB_HOST=
# Port use to connect to the database server # Port use to connect to the database server
# Should use the default port if not set # Should use the default port if not set
LD_DB_PORT= LD_DB_PORT=
# Any additional options to pass to the database (default: {})
LD_DB_OPTIONS=

View file

@ -150,6 +150,12 @@ Values: `Integer` | Default = None
The port of the database server. The port of the database server.
Should use the default port if left empty, for example `5432` for PostgresSQL. 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` ### `LD_FAVICON_PROVIDER`
Values: `String` | Default = `https://t1.gstatic.com/faviconV2?url={url}&client=SOCIAL&type=FAVICON` Values: `String` | Default = `https://t1.gstatic.com/faviconV2?url={url}&client=SOCIAL&type=FAVICON`

View file

@ -10,6 +10,7 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/ https://docs.djangoproject.com/en/2.2/ref/settings/
""" """
import json
import os import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # 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_USER = os.getenv('LD_DB_USER', 'linkding')
LD_DB_PASSWORD = os.getenv('LD_DB_PASSWORD', None) LD_DB_PASSWORD = os.getenv('LD_DB_PASSWORD', None)
LD_DB_PORT = os.getenv('LD_DB_PORT', 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': if LD_DB_ENGINE == 'postgres':
default_database = { default_database = {
@ -213,11 +215,13 @@ if LD_DB_ENGINE == 'postgres':
'PASSWORD': LD_DB_PASSWORD, 'PASSWORD': LD_DB_PASSWORD,
'HOST': LD_DB_HOST, 'HOST': LD_DB_HOST,
'PORT': LD_DB_PORT, 'PORT': LD_DB_PORT,
'OPTIONS': LD_DB_OPTIONS,
} }
else: else:
default_database = { default_database = {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'data', 'db.sqlite3'), 'NAME': os.path.join(BASE_DIR, 'data', 'db.sqlite3'),
'OPTIONS': LD_DB_OPTIONS,
} }
DATABASES = { DATABASES = {