mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-10 06:04:15 +00:00
Add postgres as database engine (#388)
* Add postgres as database engine * Fix sissbruecker review * replace psycopg2 by psycopg2-binary * Fix Docker setup * Polish docs Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
parent
7b03ceab98
commit
13e0516961
7 changed files with 96 additions and 13 deletions
18
.env.sample
18
.env.sample
|
@ -27,3 +27,21 @@ 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 settings
|
||||
# These are currently only required for configuring PostreSQL.
|
||||
# By default, linkding uses SQLite for which you don't need to configure anything.
|
||||
|
||||
# Database engine, can be sqlite (default) or postgres
|
||||
LD_DB_ENGINE=
|
||||
# Database name (default: linkding)
|
||||
LD_DB_DATABASE=
|
||||
# Username to connect to the database server (default: linkding)
|
||||
LD_DB_USER=
|
||||
# Password to connect to the database server
|
||||
LD_DB_PASSWORD=
|
||||
# The hostname where the database is hosted (default: localhost)
|
||||
LD_DB_HOST=
|
||||
# Port use to connect to the database server
|
||||
# Should use the default port if not set
|
||||
LD_DB_PORT=
|
||||
|
|
|
@ -10,7 +10,7 @@ RUN npm run build
|
|||
|
||||
|
||||
FROM python:3.10.6-slim-buster AS python-base
|
||||
RUN apt-get update && apt-get -y install build-essential
|
||||
RUN apt-get update && apt-get -y install build-essential libpq-dev
|
||||
WORKDIR /etc/linkding
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ RUN mkdir /opt/venv && \
|
|||
|
||||
|
||||
FROM python:3.10.6-slim-buster as final
|
||||
RUN apt-get update && apt-get -y install mime-support
|
||||
RUN apt-get update && apt-get -y install mime-support libpq-dev
|
||||
WORKDIR /etc/linkding
|
||||
# copy prod dependencies
|
||||
COPY --from=prod-deps /opt/venv /opt/venv
|
||||
|
|
|
@ -53,7 +53,11 @@ The name comes from:
|
|||
|
||||
## Installation
|
||||
|
||||
linkding is designed to be run with container solutions like [Docker](https://docs.docker.com/get-started/). The Docker image is compatible with ARM platforms, so it can be run on a Raspberry Pi.
|
||||
linkding is designed to be run with container solutions like [Docker](https://docs.docker.com/get-started/).
|
||||
The Docker image is compatible with ARM platforms, so it can be run on a Raspberry Pi.
|
||||
|
||||
By default, linkding uses SQLite as a database.
|
||||
Alternatively linkding supports PostgreSQL, see the [database options](docs/Options.md#LD_DB_ENGINE) for more information.
|
||||
|
||||
### Using Docker
|
||||
|
||||
|
|
|
@ -108,3 +108,44 @@ 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`
|
||||
|
||||
Database engine used by linkding to store data.
|
||||
Currently, linkding supports SQLite and PostgreSQL.
|
||||
By default, linkding uses SQLite, for which you don't need to configure anything.
|
||||
All the other database variables below are only required for configured PostgresSQL.
|
||||
|
||||
### `LD_DB_DATABASE`
|
||||
|
||||
Values: `String` | Default = `linkding`
|
||||
|
||||
The name of the database.
|
||||
|
||||
### `LD_DB_USER`
|
||||
|
||||
Values: `String` | Default = `linkding`
|
||||
|
||||
The name of the user to connect to the database server.
|
||||
|
||||
### `LD_DB_PASSWORD`
|
||||
|
||||
Values: `String` | Default = None
|
||||
|
||||
The password of the user to connect to the database server.
|
||||
The password must be configured when using a database other than SQLite, there is no default value.
|
||||
|
||||
### `LD_DB_HOST`
|
||||
|
||||
Values: `String` | Default = `localhost`
|
||||
|
||||
The hostname or IP of the database server.
|
||||
|
||||
### `LD_DB_PORT`
|
||||
|
||||
Values: `Integer` | Default = None
|
||||
|
||||
The port of the database server.
|
||||
Should use the default port if left empty, for example `5432` for PostgresSQL.
|
||||
|
|
|
@ -12,6 +12,7 @@ django-widget-tweaks==1.4.12
|
|||
django4-background-tasks==1.2.7
|
||||
djangorestframework==3.13.1
|
||||
idna==3.3
|
||||
psycopg2==2.9.5
|
||||
python-dateutil==2.8.2
|
||||
pytz==2022.2.1
|
||||
requests==2.28.1
|
||||
|
|
|
@ -17,6 +17,7 @@ django4-background-tasks==1.2.7
|
|||
djangorestframework==3.13.1
|
||||
idna==3.3
|
||||
libsass==0.21.0
|
||||
psycopg2-binary==2.9.5
|
||||
python-dateutil==2.8.2
|
||||
pytz==2022.2.1
|
||||
rcssmin==1.1.0
|
||||
|
|
|
@ -79,16 +79,6 @@ DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
|||
|
||||
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
|
||||
|
||||
|
@ -204,3 +194,31 @@ trusted_origins = os.getenv('LD_CSRF_TRUSTED_ORIGINS', '')
|
|||
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_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)
|
||||
|
||||
if LD_DB_ENGINE == 'postgres':
|
||||
default_database = {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': LD_DB_DATABASE,
|
||||
'USER': LD_DB_USER,
|
||||
'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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue