diff --git a/config/runtime.exs b/config/runtime.exs index 97334c303b..db8e1c0abc 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -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" -> diff --git a/website/docs/configuration/environment_variables.md b/website/docs/configuration/environment_variables.md index 75765353e7..7a21e97920 100644 --- a/website/docs/configuration/environment_variables.md +++ b/website/docs/configuration/environment_variables.md @@ -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 |