Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postgres as database engine #388

Merged
merged 5 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ LD_AUTH_PROXY_LOGOUT_URL=
# List of trusted origins from which to accept POST requests
# See docs/Options.md for more details
LD_CSRF_TRUSTED_ORIGINS=

#Database engine can be sqlite (default) or postgres
LD_DB_ENGINE=sqlite
#Database name (default : linkding)
LD_DB_DATABASE=
sissbruecker marked this conversation as resolved.
Show resolved Hide resolved
#username/login for the database
LD_DB_LOGIN=
#password for the database
LD_DB_PASSWORD=
#Database Hostname (default : localhost)
LD_DB_HOST=
#Database port (if not set, the default database port is used)
LD_DB_PORT=
36 changes: 36 additions & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,39 @@ Note that the setting **must** include the correct protocol (`https` or `http`),
Multiple origins can be specified by separating them with a comma (`,`).

This setting is adopted from the Django framework used by linkding, more information on the setting is available in the [Django documentation](https://docs.djangoproject.com/en/4.0/ref/settings/#std-setting-CSRF_TRUSTED_ORIGINS).

### `LD_DB_ENGINE`

Values: `'postgres'` or `'sqlite'` | Default = `'sqlite'`
tomamplius marked this conversation as resolved.
Show resolved Hide resolved

Database engine can be sqlite (default) or postgres

### `LD_DB_DATABASE`

Values: `String` | Default = `'linkding'`

Database name (default : linkding)

### `LD_DB_LOGIN`

Values: `String` | Default = `'linkding'`

username/login for the database

### `LD_DB_PASSWORD`

Values: `String` | Default = None

Password for the database

### `LD_DB_HOST`

Values: `String` | Default = `'localhost'`

Database Hostname (default : localhost)

### `LD_DB_PORT`

Values: `Integer` | Default = None

Database port (if not set, the default database port is used)
38 changes: 29 additions & 9 deletions siteroot/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@

WSGI_APPLICATION = 'siteroot.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'data', 'db.sqlite3'),
}
}

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -204,3 +195,32 @@
if trusted_origins:
CSRF_TRUSTED_ORIGINS = trusted_origins.split(',')

# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

LD_DB_ENGINE = os.getenv('LD_DB_ENGINE', 'sqlite')
LD_DB_HOST = os.getenv('LD_DB_HOST', 'localhost')
LD_DB_DATABASE = os.getenv('LD_DB_DATABASE', 'linkding')
LD_DB_LOGIN = os.getenv('LD_DB_LOGIN', 'linkding')
tomamplius marked this conversation as resolved.
Show resolved Hide resolved
LD_DB_PASSWORD = os.getenv('LD_DB_PASSWORD', '')
LD_DB_PORT = os.getenv('LD_DB_PORT', '')
tomamplius marked this conversation as resolved.
Show resolved Hide resolved

if LD_DB_ENGINE == "postgres" :
default_database = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
tomamplius marked this conversation as resolved.
Show resolved Hide resolved
'NAME': LD_DB_DATABASE,
'USER': LD_DB_LOGIN,
'PASSWORD': LD_DB_PASSWORD,
'HOST': LD_DB_HOST,
'PORT': LD_DB_PORT,
}
else:
default_database = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'data', 'db.sqlite3'),
}

DATABASES = {
'default': default_database
}