mirror of
https://github.com/laurent22/joplin.git
synced 2025-03-20 20:55:18 +02:00
Server: Add in ability to use Postgres connection string in configuration (#6836)
This commit is contained in:
parent
5b3f07f3c5
commit
01d451f72a
@ -34,7 +34,9 @@ You can setup the container to either use an existing PostgreSQL server, or conn
|
||||
|
||||
### Using an existing PostgreSQL server
|
||||
|
||||
To use an existing PostgresSQL server, set the following environment variables in the .env file:
|
||||
To use an existing PostgresSQL server, you can variables in the .env file. Either:
|
||||
|
||||
#### Individual variables
|
||||
|
||||
```conf
|
||||
DB_CLIENT=pg
|
||||
@ -45,6 +47,13 @@ POSTGRES_PORT=5432
|
||||
POSTGRES_HOST=localhost
|
||||
```
|
||||
|
||||
#### Connection String
|
||||
|
||||
```conf
|
||||
DB_CLIENT=pg
|
||||
POSTGRES_CONNECTION_STRING=postgresql://username:password@your_joplin_postgres_server:5432/joplin
|
||||
```
|
||||
|
||||
Ensure that the provided database and user exist as Joplin Server will not create them. When running on macOS or Windows through Docker Desktop, a mapping of localhost is made automatically. On Linux, you can add `--net=host --add-host=host.docker.internal:127.0.0.1` to the `docker run` command line to make the mapping happen. Any other `POSTGRES_HOST` than localhost or 127.0.0.1 should work as expected without further action.
|
||||
|
||||
### Using docker-compose
|
||||
|
@ -70,7 +70,7 @@ function markPasswords(o: Record<string, any>): Record<string, any> {
|
||||
const output: Record<string, any> = {};
|
||||
|
||||
for (const k of Object.keys(o)) {
|
||||
if (k.toLowerCase().includes('password') || k.toLowerCase().includes('secret')) {
|
||||
if (k.toLowerCase().includes('password') || k.toLowerCase().includes('secret') || k.toLowerCase().includes('connectionstring')) {
|
||||
output[k] = '********';
|
||||
} else {
|
||||
output[k] = o[k];
|
||||
|
@ -42,9 +42,18 @@ function databaseConfigFromEnv(runningInDocker: boolean, env: EnvVariables): Dat
|
||||
};
|
||||
|
||||
if (env.DB_CLIENT === 'pg') {
|
||||
return {
|
||||
const databaseConfig: DatabaseConfig = {
|
||||
...baseConfig,
|
||||
client: DatabaseConfigClient.PostgreSQL,
|
||||
};
|
||||
if (env.POSTGRES_CONNECTION_STRING) {
|
||||
return {
|
||||
...databaseConfig,
|
||||
connectionString: env.POSTGRES_CONNECTION_STRING,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
...databaseConfig,
|
||||
name: env.POSTGRES_DATABASE,
|
||||
user: env.POSTGRES_USER,
|
||||
password: env.POSTGRES_PASSWORD,
|
||||
@ -52,6 +61,7 @@ function databaseConfigFromEnv(runningInDocker: boolean, env: EnvVariables): Dat
|
||||
host: databaseHostFromEnv(runningInDocker, env) || 'localhost',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...baseConfig,
|
||||
|
@ -45,6 +45,7 @@ export interface DbConfigConnection {
|
||||
database?: string;
|
||||
filename?: string;
|
||||
password?: string;
|
||||
connectionString?: string;
|
||||
}
|
||||
|
||||
export interface QueryContext {
|
||||
@ -76,6 +77,9 @@ export function makeKnexConfig(dbConfig: DatabaseConfig): KnexDatabaseConfig {
|
||||
|
||||
if (dbConfig.client === 'sqlite3') {
|
||||
connection.filename = dbConfig.name;
|
||||
} else {
|
||||
if (dbConfig.connectionString) {
|
||||
connection.connectionString = dbConfig.connectionString;
|
||||
} else {
|
||||
connection.database = dbConfig.name;
|
||||
connection.host = dbConfig.host;
|
||||
@ -83,6 +87,7 @@ export function makeKnexConfig(dbConfig: DatabaseConfig): KnexDatabaseConfig {
|
||||
connection.user = dbConfig.user;
|
||||
connection.password = dbConfig.password;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
client: dbConfig.client,
|
||||
|
@ -55,6 +55,7 @@ const defaultEnvValues: EnvVariables = {
|
||||
POSTGRES_USER: 'joplin',
|
||||
POSTGRES_HOST: '',
|
||||
POSTGRES_PORT: 5432,
|
||||
POSTGRES_CONNECTION_STRING: '',
|
||||
|
||||
// This must be the full path to the database file
|
||||
SQLITE_DATABASE: '',
|
||||
@ -124,6 +125,7 @@ export interface EnvVariables {
|
||||
POSTGRES_USER: string;
|
||||
POSTGRES_HOST: string;
|
||||
POSTGRES_PORT: number;
|
||||
POSTGRES_CONNECTION_STRING: string;
|
||||
|
||||
SQLITE_DATABASE: string;
|
||||
|
||||
|
@ -65,6 +65,7 @@ export interface DatabaseConfig {
|
||||
port?: number;
|
||||
user?: string;
|
||||
password?: string;
|
||||
connectionString?: string;
|
||||
asyncStackTraces?: boolean;
|
||||
slowQueryLogEnabled?: boolean;
|
||||
slowQueryLogMinDuration?: number;
|
||||
|
Loading…
x
Reference in New Issue
Block a user