|
|
|
@@ -1,5 +1,5 @@ |
|
|
|
from typing import Any, Literal, Optional |
|
|
|
from urllib.parse import quote_plus |
|
|
|
from urllib.parse import parse_qsl, quote_plus |
|
|
|
|
|
|
|
from pydantic import Field, NonNegativeInt, PositiveFloat, PositiveInt, computed_field |
|
|
|
from pydantic_settings import BaseSettings |
|
|
|
@@ -166,14 +166,28 @@ class DatabaseConfig(BaseSettings): |
|
|
|
default=False, |
|
|
|
) |
|
|
|
|
|
|
|
@computed_field |
|
|
|
@computed_field # type: ignore[misc] |
|
|
|
@property |
|
|
|
def SQLALCHEMY_ENGINE_OPTIONS(self) -> dict[str, Any]: |
|
|
|
# Parse DB_EXTRAS for 'options' |
|
|
|
db_extras_dict = dict(parse_qsl(self.DB_EXTRAS)) |
|
|
|
options = db_extras_dict.get("options", "") |
|
|
|
# Always include timezone |
|
|
|
timezone_opt = "-c timezone=UTC" |
|
|
|
if options: |
|
|
|
# Merge user options and timezone |
|
|
|
merged_options = f"{options} {timezone_opt}" |
|
|
|
else: |
|
|
|
merged_options = timezone_opt |
|
|
|
|
|
|
|
connect_args = {"options": merged_options} |
|
|
|
|
|
|
|
return { |
|
|
|
"pool_size": self.SQLALCHEMY_POOL_SIZE, |
|
|
|
"max_overflow": self.SQLALCHEMY_MAX_OVERFLOW, |
|
|
|
"pool_recycle": self.SQLALCHEMY_POOL_RECYCLE, |
|
|
|
"pool_pre_ping": self.SQLALCHEMY_POOL_PRE_PING, |
|
|
|
"connect_args": {"options": "-c timezone=UTC"}, |
|
|
|
"connect_args": connect_args, |
|
|
|
} |
|
|
|
|
|
|
|
|