|
| 1 | +# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com> |
| 2 | +# SPDX-FileCopyrightText: 2026 CARIAD SE |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | + |
| 6 | +from pydantic import BaseModel, ConfigDict, Field |
| 7 | + |
| 8 | + |
| 9 | +class PostgresConnection(BaseModel): |
| 10 | + """ |
| 11 | + PostgreSQL connection configuration and HikariCP pool settings. |
| 12 | + """ |
| 13 | + |
| 14 | + model_config = ConfigDict(extra="forbid") |
| 15 | + |
| 16 | + url: str = Field( |
| 17 | + ..., |
| 18 | + description=("The database URL in JDBC format."), |
| 19 | + ) |
| 20 | + |
| 21 | + provider_schema: str = Field( |
| 22 | + default="public", |
| 23 | + alias="schema", |
| 24 | + description=("The name of the database to use."), |
| 25 | + ) |
| 26 | + |
| 27 | + username: str = Field( |
| 28 | + ..., |
| 29 | + description=("The username to use for authentication."), |
| 30 | + ) |
| 31 | + |
| 32 | + password: str = Field( |
| 33 | + default_factory=str, |
| 34 | + description=("The password to use for authentication."), |
| 35 | + ) |
| 36 | + |
| 37 | + sslmode: str = Field( |
| 38 | + default="verify-full", |
| 39 | + description='The SSL mode to use, one of "disable", "allow", "prefer", "require", ' |
| 40 | + '"verify-ca" or "verify-full". See: ' |
| 41 | + "https://jdbc.postgresql.org/documentation/ssl/#configuring-the-client", |
| 42 | + ) |
| 43 | + |
| 44 | + sslcert: str | None = Field( |
| 45 | + None, |
| 46 | + description="The full path of the certificate file. See: https://jdbc.postgresql.org/documentation/head/connect.html", |
| 47 | + ) |
| 48 | + |
| 49 | + sslkey: str | None = Field( |
| 50 | + None, |
| 51 | + description="The full path of the key file. See: https://jdbc.postgresql.org/documentation/head/connect.html", |
| 52 | + ) |
| 53 | + |
| 54 | + sslrootcert: str | None = Field( |
| 55 | + None, |
| 56 | + description="The full path of the root certificate file. See: " |
| 57 | + "https://jdbc.postgresql.org/documentation/head/connect.html", |
| 58 | + ) |
| 59 | + |
| 60 | + connection_timeout: int | None = Field( |
| 61 | + None, |
| 62 | + description="Maximum milliseconds to wait for connections from the pool. See: " |
| 63 | + "https://github.com/brettwooldridge/HikariCP#frequently-used", |
| 64 | + ) |
| 65 | + |
| 66 | + idle_timeout: int | None = Field( |
| 67 | + None, |
| 68 | + description="Maximum milliseconds a connection may sit idle in the pool. Requires " |
| 69 | + "minimum_idle < maximum_pool_size. See: " |
| 70 | + "https://github.com/brettwooldridge/HikariCP#frequently-used", |
| 71 | + ) |
| 72 | + |
| 73 | + keepalive_time: int | None = Field( |
| 74 | + None, |
| 75 | + description="Frequency in milliseconds that the pool will keep an idle connection " |
| 76 | + "alive. Must be lower than max_lifetime. See: " |
| 77 | + "https://github.com/brettwooldridge/HikariCP#frequently-used", |
| 78 | + ) |
| 79 | + |
| 80 | + max_lifetime: int | None = Field( |
| 81 | + None, |
| 82 | + description=( |
| 83 | + "Maximum lifetime of a connection in milliseconds. See: " |
| 84 | + "https://github.com/brettwooldridge/HikariCP#frequently-used" |
| 85 | + ), |
| 86 | + ) |
| 87 | + |
| 88 | + maximum_pool_size: int | None = Field( |
| 89 | + None, |
| 90 | + description="Maximum size of the connection pool. See: https://github.com/brettwooldridge/HikariCP#frequently-used", |
| 91 | + ) |
| 92 | + |
| 93 | + minimum_idle: int | None = Field( |
| 94 | + None, |
| 95 | + description="Minimum number of idle connections that the pool tries to maintain. " |
| 96 | + "See: https://github.com/brettwooldridge/HikariCP#frequently-used", |
| 97 | + ) |
0 commit comments