Skip to content

Commit

Permalink
feat: support accessing PostgreSQL on unix domain sockets (teslamate-…
Browse files Browse the repository at this point in the history
…org#4456)

* Support configuring teslamate with unix domain sockets for Postgres

* docs

* reorder

* format, cleanup

* style: update environment variables documentation for DATABASE_SOCKET_DIR formatting

---------

Co-authored-by: Jakob Lichterfeld <jakob-lichterfeld@gmx.de>
  • Loading branch information
2 people authored and senmizu committed Jan 14, 2025
1 parent b111a81 commit 1f24729
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 14 additions & 6 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,22 @@ end
config :teslamate,
default_geofence: System.get_env("DEFAULT_GEOFENCE")

case System.get_env("DATABASE_SOCKET_DIR") do
nil ->
config :teslamate, TeslaMate.Repo,
username: Util.fetch_env!("DATABASE_USER", all: "postgres"),
password: Util.fetch_env!("DATABASE_PASS", all: "postgres"),
hostname: Util.fetch_env!("DATABASE_HOST", all: "localhost"),
port: System.get_env("DATABASE_PORT", "5432")

socket_dir ->
config :teslamate, TeslaMate.Repo, socket_dir: socket_dir
end

config :teslamate, TeslaMate.Repo,
username: Util.fetch_env!("DATABASE_USER", all: "postgres"),
password: Util.fetch_env!("DATABASE_PASS", all: "postgres"),
database: Util.fetch_env!("DATABASE_NAME", dev: "teslamate_dev", test: "teslamate_test"),
hostname: Util.fetch_env!("DATABASE_HOST", all: "localhost"),
port: System.get_env("DATABASE_PORT", "5432"),
pool_size: System.get_env("DATABASE_POOL_SIZE", "10") |> String.to_integer(),
timeout: System.get_env("DATABASE_TIMEOUT", "60000") |> String.to_integer()
timeout: System.get_env("DATABASE_TIMEOUT", "60000") |> String.to_integer(),
database: Util.fetch_env!("DATABASE_NAME", dev: "teslamate_dev", test: "teslamate_test")

case System.get_env("DATABASE_SSL") do
"true" ->
Expand Down
9 changes: 5 additions & 4 deletions website/docs/configuration/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ TeslaMate accepts the following environment variables for runtime configuration:
| Variable Name | Description | Default Value |
| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| **ENCRYPTION_KEY** | A key used to encrypt the Tesla API tokens (**required**) | |
| **DATABASE_USER** | Username (**required**) | |
| **DATABASE_PASS** | User password (**required**) | |
| **DATABASE_NAME** | The database to connect to (**required**) | |
| **DATABASE_HOST** | Hostname of the database server (**required**) | |
| **DATABASE_USER** | Username | |
| **DATABASE_PASS** | User password | |
| **DATABASE_NAME** | The database to connect to | |
| **DATABASE_HOST** | Hostname of the database server | |
| **DATABASE_PORT** | Port of the database server | 5432 |
| **DATABASE_SOCKET_DIR** | Local path containing unix socket for database if that connection mechanic is preferred. Provide one of DATABASE*SOCKET_DIR and DATABASE*(USER\|PASS\|HOST\|PORT) | |
| **DATABASE_POOL_SIZE** | Size of the database connection pool | 10 |
| **DATABASE_TIMEOUT** | The time in milliseconds to wait for database query calls to finish | 60000 |
| **DATABASE_SSL** | Set to `true` if SSL should be enabled or `noverify` if certificate verification should not be performed. | false |
Expand Down

0 comments on commit 1f24729

Please sign in to comment.